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 |
大牛看看我的代码,为什么wa?#include <cstdio> #include <memory> #include <algorithm> using namespace std; struct node { int winner; int loser; }; int main() { int n,m,i,count = 0; int* a; bool changed; node* result; scanf("%d %d",&n,&m); a = new int[n]; result = new node[m]; for(i = 0;i < m;i ++) { scanf("%d %d",&result[i].winner,&result[i].loser); result[i].winner--; result[i].loser--; } memset(a,0,n*sizeof(a[0])); while(1) { changed = false; for(i = 0;i < m;i ++) { if(a[result[i].winner] <= a[result[i].loser]) { a[result[i].winner] = a[result[i].loser]+1; changed = true; } } if(!changed) break; } sort(a,a+n); for(i = 1;i < n;i ++) { if(a[i] != a[i-1]) count ++; else break; } if(count == n-1) count = n; printf("%d\n",count); delete[] result; delete[] a; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator