-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10775.cpp
More file actions
42 lines (35 loc) · 740 Bytes
/
BOJ_10775.cpp
File metadata and controls
42 lines (35 loc) · 740 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
// 21 / 12 / 31
#include <iostream>
#include <vector>
using namespace std;
int g, p, answer;
vector<int> parent;
vector<int> plane;
int whoParent(int node)
{
if (parent[node] == node)
return node;
return parent[node] = whoParent(parent[node]);
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> g >> p;
parent.assign(g + 1, 0);
plane.assign(p, 0);
for (int i = 1; i <= g; i++)
parent[i] = i;
for (int i = 0; i < p; i++)
cin >> plane[i];
for (int i = 0; i < p; i++)
{
int x = whoParent(plane[i]);
if (whoParent(x) == 0)
break;
answer++;
parent[x] = parent[x - 1];
}
cout << answer;
return 0;
}