-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path247.cpp
More file actions
executable file
·56 lines (52 loc) · 988 Bytes
/
247.cpp
File metadata and controls
executable file
·56 lines (52 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[30];
vector<int > color;
vector <int> parent;
int cycle_end;
int cycle_start;
bool dfs(int i)
{
color[i]=1;
for(int u: adj[i])
{
if(color[u]==0)
{
parent[u]=i;
if (dfs(u)) return true;
}
else if(color[u]==1)
{
cycle_end=i;
cycle_start=u;
return true;
}
}
color[i]=2;
return false;
}
int main()
{
while(true)
{
int n,e;
cin>>n>>e;
if(n==0&&e==0)break;
unordered_map<string,int> umap;
string p,q;
int count=0;
for(int i=1; i<=e; i++)
{
cin>>p>>q;
if(umap[p]!=0)
{
umap[p]=count++;
}
if(umap[q]!=0)
{
umap[q]=count++;
}
adj[umap[p]].push_back(umap[q]);
}
}
}