Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
poj真是奇怪,一道题,交两次,一次TLE,一次16ms#include<iostream> using namespace std; int map[6000]; struct node { int from,to,cost; }path[6000]; int n,m,w; /*void show(int i) { printf("depot: %d dis: %d\n",path[i].to,map[path[i].to]); }*/ int main() { int flag,i,j,cnt,mincow; scanf("%d",&cnt); while(cnt-->0) { scanf("%d%d%d",&n,&m,&w); memset(map,999999,(n+1)*sizeof(int)); map[1]=0; for(i=0;i<2*m;i+=2) { scanf("%d%d%d",&path[i].from,&path[i].to,&path[i].cost); path[i+1].to=path[i].from; path[i+1].from=path[i].to; path[i+1].cost=path[i].cost; } for(i=2*m;i<2*m+w;i++) { scanf("%d%d%d",&path[i].from,&path[i].to,&path[i].cost); path[i].cost=-path[i].cost; } flag=1; while(flag&&map[1]==0) { flag=0; for(i=0;i<2*m+w;i++) { if(map[path[i].from]+path[i].cost<map[path[i].to]) {map[path[i].to]=map[path[i].from]+path[i].cost;flag=1;/*show(i);*/} } } if(map[1]==0) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator