记录编号 |
472008 |
评测结果 |
AAAAAAA |
题目名称 |
[NOIP 2003]神经网络 |
最终得分 |
100 |
用户昵称 |
东林桂香 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.011 s |
提交时间 |
2017-11-07 08:09:44 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define maxn 205
using namespace std;
struct Ha{
int next,cost;
};
int n,p,x,y,z,pos,ru[maxn],chu[maxn],li[maxn],bc[maxn],c[maxn],biao[maxn],u[maxn];
vector<Ha>ha[maxn];
vector<int>r;
vector<int>cc;
int main(){
freopen("sjwl.in","r",stdin);
freopen("sjwl.out","w",stdout);
scanf("%d%d",&n,&p);pos=n;
for(int i=1;i<=n;i++)scanf("%d%d",&c[i],&u[i]),chu[i]=0,ru[i]=0;
for(int i=1;i<=p;i++){
scanf("%d%d%d",&x,&y,&z);
Ha ppp;ppp.next=y;ppp.cost=z;
chu[x]++;ru[y]++;
ha[x].push_back(ppp);
}
for(int i=1;i<=n;i++){
if(chu[i]==0){
cc.push_back(i);biao[i]=1;pos--;
}
if(!ru[i])r.push_back(i),li[i]=1;
}
while(pos>0){
while(r.size()>0){
int cnt=r.size()-1;
if(li[r[cnt]]==0)c[r[cnt]]-=u[r[cnt]];
if(c[r[cnt]]>0){
Ha oo;
for(int i=0;i<ha[r[cnt]].size();i++){
oo=ha[r[cnt]][i];
// cout<<r[r.size()-1]<<" "<<oo.next<<" !!! "<<c[r[r.size()-1]]*oo.cost<<endl;
c[oo.next]+=(c[r[cnt]]*oo.cost);
biao[r[cnt]]=1;
}
}
for(int i=0;i<ha[r[cnt]].size();i++)
ru[ha[r[cnt]][i].next]--;
r.pop_back();
pos--;
}
for(int i=1;i<=n;i++)
if(ru[i]==0&&!biao[i])
r.push_back(i);
// cout<<"正在运行中(蛤,你要TLE了)..."<<pos<<endl;
}
int ans=0;
for(int i=0;i<cc.size();i++){
if(li[cc[i]]==0)c[cc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