标签:des blog http io ar os for sp strong
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int mat[510][510]; int mark[510]; int ans[510]; int main() { int n,m,i,j,k; int l,r; while(scanf("%d%d",&n,&m)!=EOF) { k=0; memset(mat,0,sizeof(mat)); memset(mark,0,sizeof(mark)); //memset(ans,0,sizeof(ans)); while(m--) { scanf("%d%d",&l,&r); if(mat[l][r]==0) { mat[l][r]=1; mark[r]++; } } for(i=0;i<n;i++) { int flag=-1; for(j=1;j<=n;j++) { if(mark[j]==0) { ans[k++]=j; mark[j]=-1; flag=j; break; } } if(flag!=-1) { for(j=1;j<=n;j++) { if(mat[flag][j]==1) { mark[j]--; } } } } for(i=0;i<n-1;i++) printf("%d ",ans[i]); printf("%d\n",ans[n-1]); } return 0; }
标签:des blog http io ar os for sp strong
原文地址:http://www.cnblogs.com/sola1994/p/4074309.html