Topic Description Description
A network of friends, if a knows B, then if a gets a message for the first time, it passes the message to B, and to everyone who knows it.
If a knows b,b not necessarily know a.
All the people from 1 to n numbers, give all "understanding" relationship, ask if I release a new message, then will pass a number of messages, this message back to I,1<=i<=n. Input 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, represents a knowing B. 1<=a, B<=n. The cognitive relationship may be repeated, but a line of two numbers will not be the same.
Output Description Description
Altogether n rows, one character T or F per line. Line I if it is T, I send a new message back to I; if it is F, I send a new message that does not pass back to I.
Sample Input For example
4 6
1 2
2 3
4 1
3 1
1 3
2 3 Sample Output
T
T
T
F range and hint data Size & Hint
n<=1000
1<=a, B<=n
#include <iostream>
#include <memory.h>
#include <set>
using namespace std;
int n;
int m;
Set<int> node[1001];
int visited[1001];
int des;
BOOL Dfs (int i)
{
if (visited[i] = 1&&i==des) return
true;
if (visited[i] = = 1) return
false;
Visited[i] = 1;
For (Set<int>::iterator It=node[i].begin (), It!=node[i].end (); it++)
if (Dfs (*it) ==true) return
True ;
return false;
}
int main ()
{
cin >> n >> m;
for (int i=0;i<m;i++)
{
int a, b;
Cin >> a >> b;
Node[a].insert (b);
}
for (int i=1;i<=n;i++)
{
memset (visited, 0, sizeof (visited));
des = i;
if (Dfs (i))
cout << "T" <<endl;
else
cout << "F" << Endl;
}
return 0;
}