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 |
帮我看看吧,实在看不出来了,大哥们给组数据吧,谢谢了#include <cstdlib> #include <iostream> #include <memory.h> #include <stdio.h> using namespace std; int d[1001][1001],rd[1001],cd[1001]; bool p1[1001]; bool p2[1001]; bool rank[1001]; int main(int argc, char *argv[]) {int n,m; int i,j,k,a,b,h; int count,total; while(scanf("%d%d",&n,&m)!=EOF){ total=0; memset(rd,0,sizeof(rd)); memset(cd,0,sizeof(cd)); memset(d,0,sizeof(d)); memset(p1,0,sizeof(p1)); memset(p2,0,sizeof(p2)); memset(rank,0,sizeof(rank)); while(m--){ scanf("%d%d",&a,&b); if(d[a][b]==0){ d[a][b]=1; rd[b]++; cd[a]++; } } for(k=1;k<=n;k++){ count=0; for(i=1;i<=n;i++){ if(rd[i]==0&&!p1[i]){ p1[i]=1; count++; h=i; } } if(count==0) break; else if(count==1){ for(j=1;j<=n;j++) if(d[h][j]&&!p1[j]) rd[j]--; if(rank[h]==0) total++; rank[h]=1; } else { break; } } //printf("%d\n",total); for(k=1;k<=n;k++){ count=0; for(i=1;i<=n;i++){ if(cd[i]==0&&!p2[i]){ count++; p2[i]=1; h=i; } } if(count==0) break; else if(count==1){ for(j=1;j<=n;j++) if(d[j][h]&&!p2[j]) cd[j]--; if(rank[h]==0) total++; rank[h]=1; } else { break; } } printf("%d\n",total); } //system("PAUSE"); return EXIT_SUCCESS; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator