Let the leader go first. Time limit:2000ms Memory limit:65536k have questions? Dot here ^_^ Title Description
After the end of the company in a fire pull, everyone run, or run will be killed. Please do not mess, in order through the fire tunnel, speaking of order, then the problem.
According to the Chinese characteristics of the socialist culture, we strictly implement one thing, that is, let the leadership go first.
Now N people, marking from 1 to n. If a is The leader of B, you have to put a in front of B.
Then you'll have to arrange the order of everyone. I promise there must be a solution.
Enter more than one set of inputs, and then for each test data, the first row has two integersN (1 <= n <= 30000)and them (1 <= m <= 100000), each representing the number of people andThe number of subordinate existence.
Then m lines, two integers a and bper line, indicate that there is a leader of b . a and the b must be different.
Outputs the order in which each test data is queued, separated by a space.
Sample input
5 103 51 42 51 23 41 42 31 53 51 2
Sample output
1 2 3) 4 5
#include <iostream> #include <string.h>using namespace Std;int map[22000][22000];int in[30005];int s[30005 ],n,m;void Tuobu () { int i,j,k=0; for (i=1;i<=n;i++) { if (in[i]==0) {s[k++]=i; in[i]--; for (j=1;j<=n;j++) { if (map[i][j]==0) { in[j]--; }}}} for (i=0;i<k;i++) { if (i==0) cout<<s[i]; else cout<< "" <<s[i]; } Cout<<endl;} int main () { int i,j,k; while (cin>>n>>m) { int x, y; for (i=1;i<=n;i++) in[i]=0; for (i=1;i<=n;i++) for (j=1;j<=n;j++) map[i][j]=-1; for (i=0;i<m;i++) {cin>>x>>y; if (map[x][y]==-1) { in[y]++; map[x][y]=0; } } Tuobu (); }}
The sort of extension and complement