ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

神经网络

2022-08-11 18:03:20  阅读:94  来源: 互联网

标签:ch int MAX flag read 神经网络 P1038


P1038 [NOIP2003 提高组] 神经网络 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

  • tupo题
  • 用队列存激活了的点,然后从队列头的点出发能到达的点去进行松弛(累加C值)当他所有可能增加的情况都增加过了(入度为0)那么就判断他能否入队去松弛别的点
  • 答案要求输出层的C值,所以需要知道哪些是输出层(即出度为0的点),那么还要存出度
//https://www.luogu.com.cn/problem/P1038
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 10000000
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int idx, head[MAX];
struct Node
{
    int to, w, nex;
} edge[MAX];
void add(int u, int v, int w)
{
    edge[++idx] = (Node){v, w, head[u]};
    head[u] = idx;
}
queue<int> q;
int n, p, u[MAX], vis[MAX], jihuo[MAX], dutt[MAX], dutt_chu[MAX];
int c[MAX];
vector<int> s;
void input()
{
    n = read(), p = read();
    int aa, bb, cc;
    for (int i = 1; i <= n; i++)
    {
        aa = read();
        bb = read();
        c[i] = aa;
        u[i] = bb;
        if (aa)
            q.push(i);
    }
    for (int i = 1; i <= p; i++)
    {
        aa = read(), bb = read(), cc = read();
        add(aa, bb, cc);
        dutt_chu[aa]++;
        dutt[bb]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (!dutt_chu[i])
            s.push_back(i);
    }
}
void tupo()
{
    for (int i = 1; i <= n; i++)
    {
        if (dutt[i])
            c[i] = -u[i];
    }
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        for (int i = head[now]; i; i = edge[i].nex)
        {
            int to = edge[i].to;
            c[to] += c[now] * edge[i].w;
            dutt[to]--;
            if (!dutt[to] && c[to] > 0)
            {
                q.push(to);
            }
        }
    }
}
void output()
{
    bool flag = false;
    for (int i = 0; i < s.size(); i++)
    {
        if (c[s[i]] > 0)
        {

            printf("%d %d\n", s[i], c[s[i]]);
            flag = true;
        }
    }
    if (!flag)
        printf("NULL");
}
int main()
{
    input();
    tupo();
    output();
}

 

标签:ch,int,MAX,flag,read,神经网络,P1038
来源: https://www.cnblogs.com/Wang-Xianyi/p/16576977.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有