-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10775.cpp
More file actions
32 lines (28 loc) · 691 Bytes
/
10775.cpp
File metadata and controls
32 lines (28 loc) · 691 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
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int tree[100001];
int find(int x) {
if (tree[x] == x) return x;
return tree[x] = find(tree[x]);
}
int main()
{
cin.tie(0) -> sync_with_stdio(0);
int G, P; cin >> G >> P; for (int i = 0; i <= G; i++) tree[i] = i;
int result = 0;
bool full = false;
for (int i = 0; i < P; i++) {
int gi; cin >> gi; if (full) continue;
int found = find(gi);
if (found > 0) {
result++;
tree[found] = found - 1;
} else full = true;
}
cout << result;
return 0;
}