-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1209D.cpp
More file actions
37 lines (32 loc) · 857 Bytes
/
1209D.cpp
File metadata and controls
37 lines (32 loc) · 857 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
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
int dfs(vector<int> &visited, vector<vector<int>> &g, int i) {
int ans = 0;
if(!visited[i]) {
visited[i] = 1;
for(auto k : g[i]) ans += dfs(visited, g, k);
ans++;
}
return ans;
}
int main() {
int n, k; cin >> n >> k;
int ans = 0;
vpii v(k, {0, 0});
vvi g(n, vector<int>());
vi visited(n, 0);
for(int i = 0; i < k; i++) {
cin >> v[i].first >> v[i].second;
g[v[i].first - 1].push_back(v[i].second - 1);
g[v[i].second - 1].push_back(v[i].first - 1);
}
for(int i = 0; i < n; i++)
if(!visited[i])
ans += dfs(visited, g, i) - 1;
cout << k - ans << endl;
return 0;
}