Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
- #define read freopen("input.txt","r",stdin)
- #define write freopen("output.txt","w",stdout)
- const int MAXN = 107;
- map<string, vector<string>> adj;
- map<string, bool> vis;
- map<string, int> color;
- map<string, string> parent;
- int N, E;
- bool isSame = false;
- bool isCycle = false;
- void dfs(string src)
- {
- cout << src << endl;
- vis[src] = true;
- for(auto v : adj[src])
- {
- if(!vis[v])
- {
- color[v] = !color[src];
- parent[v] = src;
- dfs(v);
- }
- else
- {
- if(color[v] == color[src]) isSame = true;
- if(parent[src] != v)
- isCycle = true;
- }
- }
- }
- int main() {
- #ifndef ONLINE_JUDGE
- read;
- write;
- #endif
- fast;
- cin >> N >> E;
- for (int i = 0; i < E; i++)
- {
- string u, v;
- cin >> u >> v;
- adj[u].push_back(v);
- adj[v].push_back(u);
- }
- dfs("em");
- if(isSame) cout << "Not Possible\n" << endl;
- else cout << "Possible\n" << endl;
- if(isCycle) cout << "Cycle\n" << endl;
- else cout << "No Cycle\n" << endl;
- return 0;
- }
- /*
- 6 6
- em fa
- fa ra
- ra sh
- ko ra
- ko far
- far sh
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement