Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define d(x) cout << #x << " = " << (x) << endl;
- #define fr freopen("in.txt", "r", stdin);
- #define fw freopen("out.txt", "w", stdout);
- #define mem(x) memset((x), 0, sizeof((x)));
- #define pb push_back
- #define LL long long
- #define fastIO ios_base::sync_with_stdio(false)
- #define sf scanf
- #define pf printf
- #define sc1(x) scanf("%d", &x)
- #define sc2(x, y) scanf("%d %d", &x, &y)
- #define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z)
- #define FOR(i, x, y) for(int i=int(x); i<int(y); i++)
- #define ROF(i, x, y) for(int i=int(x-1); i>=int(y); i--)
- #define all(c) c.begin(), c.end()
- #define unq(v) sort(all(v)), (v).erase(unique(all(v)),v.end())
- #define siz 1000000
- #define MAX 100000
- //Graph
- vector<int> edge[MAX];
- vector<int> cost[MAX];
- //DFS visited node: colors: 0=white, 1=gray, 2=black
- vector<int> visited(MAX);
- //DFS validator
- int max_depth = 0;
- /////////////////DFS/////////////////////////
- void DFS(int u){
- visited[u] = 1;
- for(int v = 0; v < edge[u].size(); v++){
- if(visited[edge[u][v]] == 0){
- DFS(edge[u][v]);
- max_depth++;
- }
- }
- visited[u] = 2;
- }
- ////////////////////////////////////////////
- int main(){
- fastIO;
- fw; fr;
- int n, e;
- cin >> n >> e;
- for(int i = 0; i < e; i++){
- int x, y;
- cin >> x >> y;
- edge[x].push_back(y);
- edge[y].push_back(x);
- cost[x].push_back(1);
- cost[y].push_back(1);
- }
- //printing graph
- for(int i = 1; i <= n; i++){
- cout << "Node: " << i << endl;
- cout << "Connected with: ";
- for(int j = 0; j < edge[i].size(); j++){
- cout << edge[i][j] << " ";
- }
- cout << endl;
- }
- //running DFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs
- DFS(1);
- d(max_depth);
- return 0;
- }
- //test case
- /*
- 6 5
- 1 2
- 2 3
- 3 4
- 4 5
- 5 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement