标签:输入 ott 要求 sample ++i top mat 获得 ane
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35253 Accepted Submission(s): 13787
#include <iostream> #include <string> #include <algorithm> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define each(i,n) (int i=1;i<=(n);++i) using namespace std; int head[100004],rudu[100004]; struct node { int to,next; }bian[100004]; int top=0; int queu[100004]; void add(int a,int b) { bian[top].to=b; bian[top].next=head[a]; head[a]=top++; } int main() { int n,m; while(~scanf("%d%d",&n,&m)) { int a,b; memset(head,-1,sizeof(head)); memset(rudu,0,sizeof(rudu)); for(int i=0;i<m;i++) { cin>>a>>b; add(a,b); rudu[b]++; } int c=0; while(c<n) { for(int i=1;i<=n;i++) { if(rudu[i]==0) { queu[c++]=i; rudu[i]=-1; for(int j=head[i];j!=-1;j=bian[j].next) rudu[bian[j].to]--; break; } } } for(int i=0;i<c;i++) { printf(i==c-1?"%d\n":"%d ",queu[i]); } } return 0; }
标签:输入 ott 要求 sample ++i top mat 获得 ane
原文地址:https://www.cnblogs.com/SparkPhoneix/p/9378362.html