传送门啦

一个拓扑排序的题,感觉题目好难懂。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105; inline int read(){char ch = getchar();int f = 1 , x = 0;while(ch > '9' || ch < '0'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + ch - '0';ch = getchar();}return x * f;} int n,p,c[maxn],u[maxn],x,y,z;
int head[maxn],tot;
int in[maxn],out[maxn];
bool vis[maxn],flag; struct Edge{
int from,to,val,next;
}edge[maxn << 1]; void add(int u,int v,int w){
edge[++tot].from = u;
edge[tot].to = v;
edge[tot].val = w;
edge[tot].next = head[u];
head[u] = tot;
} void dfs(int x){
for(int i=head[x];i;i=edge[i].next){
int v = edge[i].to;
c[v] += edge[i].val * c[x];
in[v]--;
if(!in[v] && c[v] - u[v] > 0){
c[v] -= u[v];
dfs(v);
}
}
} int main(){
n = read(); p = read();
for(int i=1;i<=n;i++) {
c[i] = read(); u[i] = read();
if(c[i] > 0) vis[i] = true;
}
for(int i=1;i<=p;i++){
x = read(); y = read(); z = read();
add(x , y , z);
in[y]++; out[x]++;
}
for(int i=1;i<=n;i++)
if(vis[i]) dfs(i);
for(int i=1;i<=n;i++)
if(out[i] == 0 && c[i] > 0){
printf("%d %d\n",i,c[i]);
flag = true;
}
if(!flag) printf("NULL\n");
return 0;
}

洛谷P1038神经网络的更多相关文章

  1. 洛谷P1038 神经网络==codevs1088 神经网络

    P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...

  2. 洛谷P1038 神经网络

    P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...

  3. 洛谷——P1038 神经网络

    P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...

  4. 洛谷 P1038 神经网络 Label:拓扑排序 && 坑 60分待查

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  5. 洛谷P1038 神经网络(bfs,模拟,拓扑)

    题目背景 人工神经网络(Artificial Neural NetworkArtificialNeuralNetwork)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸 ...

  6. 洛谷 P1038 神经网络

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  7. [NOIP2003] 提高组 洛谷P1038 神经网络

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  8. 洛谷P1038神经网络题解

    题目 这个题不得不说是一道大坑题,为什么这么说呢,这题目不仅难懂,还非常适合那种被生物奥赛刷下来而来到信息奥赛的学生. 因此我们先分析一下题目的坑点. 1: 题目的图分为输入层,输出层,以及中间层. ...

  9. 洛谷P1038 神经网络题解

    注意如果是 \(if(c[i])\) 这条语句并没有说明c[i]不为负数,所以说最好老老实实的写 #include<cstdio> #define _ 0 using namespace ...

随机推荐

  1. 响应式开发(五)-----Bootstrap CSS----------Bootstrap 网格系统

    如果我们看过一些bootstrap的框架,经常看到col-sm-3等样式class. Bootstrap 提供了一套响应式.移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系 ...

  2. List of NP-complete problems

    This is a list of some of the more commonly known problems that are NP-complete when expressed as de ...

  3. 使用EntitysCodeGenerate

    http://bbs.csdn.net/topics/360256700 public DataSet xxx(DateTime start, DateTime end, string type)   ...

  4. Python高手之路【四】python函数装饰器,迭代器

    def outer(func): def inner(): print('hello') print('hello') print('hello') r = func() print('end') p ...

  5. Java基础-Date类常用方法介绍

    Java基础-Date类常用方法介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.毫秒值概念 我们在查阅Date类的API文档时,会发现这样的一句话:"The cl ...

  6. python---基础知识回顾(十)进程和线程(进程)

    前戏:进程和线程的概念 若是学过linux下的进程,线程,信号...会有更加深刻的了解.所以推荐去学习下,包括网络编程都可以去了解,尤其是对select,poll,epoll都会有更多的认识. 进程就 ...

  7. python---函数补充(变量传递),语句执行顺序(入栈顺序)

    一:函数补充 默认作为函数参数的数据,是浅拷贝传递.不是和C等语言一样,产生一个临时变量. class T: def __init__(self,num): print(id(num)) self.n ...

  8. bzoj千题计划163:bzoj1060: [ZJOI2007]时态同步

    http://www.lydsy.com/JudgeOnline/problem.php?id=1060 以激发器所在节点为根 终止节点一定是叶节点 记录点的子树内最深的终止节点 然后从根往下使用道具 ...

  9. html_entity_decode() 将 HTML 实体转成字符原型

    PHP html_entity_decode() 适用于PHP 4.3.0+,将HTML 实体转成字符. html_entity_decode(包含HTML 实体的字符串, 可选如何解码引号, 可选字 ...

  10. 环境变量ANDROID_SDK_HOME的作用

    默认情况下,开发者创建的AVD(Android Virtual Device)存放在家目录的.android下. 如果是Linux,其路径就是 /home/<your_user_name> ...