#include <iostream>
#include <vector>
#include <map>
using namespace std;
int timer = 0 ;
void dfs( int node, vector< vector< int >> & graph, vector< pair< int , int >> & time , map< pair< int , int > , string> & type) {
time [ node] .first = ++ timer;
for ( int child: graph[ node] ) {
if ( ! time [ child] .first ) {
type[ { node, child} ] = "Tree" ;
dfs( child, graph, time , type) ;
}
else if ( ! time [ child] .second )
type[ { node, child} ] = "Back" ;
else if ( time [ node] .first < time [ child] .first )
type[ { node, child} ] = "Forward" ;
else
type[ { node, child} ] = "Cross" ;
}
time [ node] .second = ++ timer;
}
using namespace std;
int main( ) {
int nodes, egdes;
cin >> nodes >> egdes;
vector< vector< int >> graph( nodes+ 1 ) ;
vector< pair< int , int >> time ( nodes+ 1 ) ; // Arrival & Departure
map< pair< int , int > , string> type;
int from, to;
while ( egdes-- ) {
cin >> from >> to;
graph[ from] .push_back ( to) ;
}
// Show Graph
cout << endl ;
for ( int node = 1 ; node <= nodes; node++ ) {
cout << node << " : " ;
for ( int child: graph[ node] )
cout << child << ' ' ;
cout << endl;
}
// dfs
cout << endl;
for ( int node = 1 ; node <= nodes; node++ )
if ( ! time [ node] .first )
dfs( node, graph, time , type) ;
// Show Types
cout << endl;
for ( auto node: type)
cout << node.first .first << " -> " << node.first .second << " is " << node.second << endl;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHRpbWVyID0gMDsKdm9pZCBkZnMoaW50IG5vZGUsIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gJmdyYXBoLCB2ZWN0b3I8cGFpcjxpbnQsIGludD4+ICZ0aW1lLCBtYXA8cGFpcjxpbnQsIGludD4sIHN0cmluZz4gJnR5cGUpewogICAgdGltZVtub2RlXS5maXJzdCA9ICsrdGltZXI7CgogICAgZm9yKGludCBjaGlsZDogZ3JhcGhbbm9kZV0pewogICAgICAgIGlmKCF0aW1lW2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