Codevs 1506 Relay
1506 Message-The solution to this problem is many, can you think of several? Time limit: 1 s space limit: 128000 KB title: Silver Issue Description Description A friend network, if a knows B, then if a first received a message, then the message will be passed to B, and all a know people. If a knows b,b does not necessarily know a. All the people numbered from 1 to N, gave all the "understanding" relationships, and asked if I had released a new message, then the message would have been sent back to I,1<=i<=n after a few passes. Enter a description input description The first line is N and M, representing the number of people and the number of cognitive relationships. The next M-line, two numbers a and b per line, indicates a knows B. 1<=a, B<=n. The cognitive relationship may be repeated, but the two-digit number of a row will not be the same. The output description outputs description altogether n lines, one character per line, T or F. Line I if it is T, I send a new message will be passed back to I; if it is F, I send a new message will not be returned to I. Sample input Sample Input4 61 22 34 13 11 32 3 Sample output sample Outputtttf data size & hintn<=10001<=a,b<=n
#include <iostream> #include <cstdio> #include <cstring>using namespace std; int N,m,a,b,i,j,k,num,ans;int T[1002][1002];int Main () {ans=0;cin >> n;for (i=1;i<=n;i++) for (j=1;j<=n;j++ ) t[i][j]=0;cin >> m;for (i=1;i<=m;i++) {cin>>a>>b;t[a][b]=1;} for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (t[i][k]&&t[k][j]) t[i][j]=1; for (i=1;i<=n;i++) if (T[i][i]) cout << ' t ' << Endl; else cout << ' F ' << Endl; return 0;}
Seriously reading the question seriously reading the question seriously
Freud algorithm Note output format
This article from the "Qhy of the" blog, reproduced please contact the author!
Codevs 1506 Messenger