void dfsVisit(vector<vector<int> >&graph, int node, vector<int>&visit,
vector<int>&father)
{
int n = graph.size();
visit[node] = 1;
for(int i = 0; i < n; i++)
if(i != node && graph[node][i] != INT_MAX)
{
if(visit[i] == 1 && i != father[node])
{
int tmp = node;
cout<<"cycle: ";
while(tmp != i)
{
cout<<tmp<<"->";
tmp = father[tmp];
}
cout<<tmp<<endl;
}
else if(visit[i] == 0)
{
father[i] = node;
dfsVisit(graph, i, visit, father);
}
}
visit[node] = 2;
}
void dfs(vector<vector<int> >&graph)
{
int n = graph.size();
vector<int> visit(n, 0);
vector<int> father(n, -1);
for(int i = 0; i < n; i++)
if(visit[i] == 0)
dfsVisit(graph, i, visit, father);
}
stack<int> tuopu;
void dfsVisit(vector<vector<int> >&graph, int node, vector<int>&visit,
vector<int>&father)
{
int n = graph.size();
visit[node] = 1;
for(int i = 0; i < n; i++)
if(i != node && graph[node][i] != INT_MAX)
{
if(visit[i] == 1 && i != father[node])
{
int tmp = node;
cout<<"cycle: ";
while(tmp != i)
{
cout<<tmp<<"->";
tmp = father[tmp];
}
cout<<tmp<<endl;
}
else if(visit[i] == 0)
{
father[i] = node;
dfsVisit(graph, i, visit, father);
}
}
visit[node] = 2;
tuopu.push(node);
}
void dfs(vector<vector<int> >&graph)
{
int n = graph.size();
vector<int> visit(n, 0);
vector<int> father(n, -1);
for(int i = 0; i < n; i++)
if(visit[i] == 0)
dfsVisit(graph, i, visit, father);
}