-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (60 loc) · 1.62 KB
/
main.cpp
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
57
58
59
60
61
62
63
64
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<utility>
#include<cmath>
using namespace std;
#include "ugraph.h"
int main(){
int N;
cin >> N;
UGraph ag(N);
string command;
while(cin >> command){
if(command == "addEdge"){
int u, v;
cin >> u >> v;
ag.addEdge(u, v);
}else if(command == "removeEdge"){
int u, v;
cin >> u >> v;
ag.removeEdge(u, v);
}else if(command == "bfs"){
int s;
cin >> s;
cout << "BFS on " << s << endl;
ag.bfs(s);
}else if(command == "dfs"){
cout << "DFS" << endl;
ag.dfs();
}else if(command == "distinctPaths"){
int u, v;
cin >> u >> v;
cout << "Are there two distinct paths between nodes " << u << " and " << v << "?" << endl;
bool res = ag.distinctPaths(u, v);
if(res)
cout << "There are two distinct paths between nodes " << u << " and " << v << "." << endl;
else
cout << "There are NO two distinct paths between nodes " << u << " and " << v << "." << endl;
}else if(command == "printBridges"){
cout << "Bridge edges of the graph are:" << endl;
ag.printBridges();
}else if(command == "printCC"){
cout << "Connected components of the graph are:" << endl;
ag.printCC();
}else if(command == "twoColoring"){
bool res = ag.twoColoring();
if(res)
cout << "Two-coloring is possible in this graph." << endl;
else
cout << "Two-coloring is NOT possible in this graph." << endl;
}else if(command == "printGraph"){
cout << "Adjacency lists of the graph are:" << endl;
ag.printGraph();
}else{
cerr << "ERROR: the command " << command << " is not found." << endl;
}
}//while
return 0;
}