-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfs.cpp
More file actions
45 lines (38 loc) · 690 Bytes
/
dfs.cpp
File metadata and controls
45 lines (38 loc) · 690 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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int N = 1e5;
vector<int> adj[N];
bool vis[N];
int edges = 0;
void dfs(int u) {
if (!vis[u]) {
vis[u] = true;
edges += adj[u].size();
for (auto v : adj[u]) {
dfs(v);
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
adj[1].push_back(2);
adj[1].push_back(4);
adj[1].push_back(3);
adj[3].push_back(1);
adj[3].push_back(4);
adj[4].push_back(3);
adj[4].push_back(1);
adj[4].push_back(2);
adj[4].push_back(6);
adj[2].push_back(1);
adj[2].push_back(4);
adj[2].push_back(6);
adj[6].push_back(2);
adj[6].push_back(4);
dfs(1);
edges /= 2;
cout << edges << "\n";
}