#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int cmp[500001], cmp_cnt;
set<int> graph[500001];
int find(int A) {
while (A != cmp[A]) cmp[A] = cmp[cmp[A]], A = cmp[A];
return A;
}
void onion(int A, int B) {
if (find(A) == find(B)) return;
cmp[find(A)] = find(B);
cmp_cnt--;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
iota(cmp, cmp + n + 1, 0);
cmp_cnt = n;
vector<pair<int, int>> bus;
while (m--) {
int u, v;
char t;
cin >> u >> v >> t;
if (t == 'A') bus.push_back({u, v});
else onion(u, v);
}
for (pair<int, int> i : bus) {
if (find(i.first) == find(i.second)) continue;
graph[find(i.first)].insert(find(i.second));
graph[find(i.second)].insert(find(i.first));
}
int ans = 0;
FOR(i, 1, n + 1) if (graph[find(i)].size() == cmp_cnt - 1) ans++;
cout << ans;
return 0;
}
Compilation message
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:42:48: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
FOR(i, 1, n + 1) if (graph[find(i)].size() == cmp_cnt - 1) ans++;
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
24960 KB |
Output is correct |
2 |
Correct |
19 ms |
23784 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
21 ms |
25728 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
51 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
25728 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23936 KB |
Output is correct |
4 |
Correct |
22 ms |
24576 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
556 ms |
57616 KB |
Output is correct |
7 |
Correct |
664 ms |
66912 KB |
Output is correct |
8 |
Correct |
27 ms |
25344 KB |
Output is correct |
9 |
Correct |
35 ms |
26744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
20 ms |
23800 KB |
Output is correct |
3 |
Correct |
19 ms |
23948 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Correct |
21 ms |
24064 KB |
Output is correct |
6 |
Correct |
20 ms |
24192 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
24192 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
19 ms |
23936 KB |
Output is correct |
12 |
Correct |
18 ms |
23840 KB |
Output is correct |
13 |
Correct |
19 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
24064 KB |
Output is correct |
16 |
Correct |
19 ms |
23784 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
20 ms |
23936 KB |
Output is correct |
20 |
Correct |
22 ms |
24576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
20 ms |
23800 KB |
Output is correct |
3 |
Correct |
19 ms |
23948 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Correct |
21 ms |
24064 KB |
Output is correct |
6 |
Correct |
20 ms |
24192 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
24192 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
19 ms |
23936 KB |
Output is correct |
12 |
Correct |
18 ms |
23840 KB |
Output is correct |
13 |
Correct |
19 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
24064 KB |
Output is correct |
16 |
Correct |
27 ms |
24576 KB |
Output is correct |
17 |
Correct |
166 ms |
31852 KB |
Output is correct |
18 |
Correct |
75 ms |
27500 KB |
Output is correct |
19 |
Correct |
221 ms |
38760 KB |
Output is correct |
20 |
Correct |
64 ms |
26480 KB |
Output is correct |
21 |
Correct |
156 ms |
36712 KB |
Output is correct |
22 |
Correct |
19 ms |
23784 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
18 ms |
23808 KB |
Output is correct |
25 |
Correct |
20 ms |
23936 KB |
Output is correct |
26 |
Correct |
22 ms |
24576 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
27 ms |
25344 KB |
Output is correct |
29 |
Correct |
35 ms |
26744 KB |
Output is correct |
30 |
Correct |
51 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
20 ms |
23800 KB |
Output is correct |
3 |
Correct |
19 ms |
23948 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Correct |
21 ms |
24064 KB |
Output is correct |
6 |
Correct |
20 ms |
24192 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
24192 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
19 ms |
23936 KB |
Output is correct |
12 |
Correct |
18 ms |
23840 KB |
Output is correct |
13 |
Correct |
19 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
24064 KB |
Output is correct |
16 |
Correct |
27 ms |
24576 KB |
Output is correct |
17 |
Correct |
166 ms |
31852 KB |
Output is correct |
18 |
Correct |
75 ms |
27500 KB |
Output is correct |
19 |
Correct |
221 ms |
38760 KB |
Output is correct |
20 |
Correct |
64 ms |
26480 KB |
Output is correct |
21 |
Correct |
156 ms |
36712 KB |
Output is correct |
22 |
Correct |
162 ms |
24960 KB |
Output is correct |
23 |
Correct |
19 ms |
23784 KB |
Output is correct |
24 |
Correct |
18 ms |
23808 KB |
Output is correct |
25 |
Correct |
21 ms |
25728 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
20 ms |
23936 KB |
Output is correct |
28 |
Correct |
22 ms |
24576 KB |
Output is correct |
29 |
Correct |
18 ms |
23808 KB |
Output is correct |
30 |
Correct |
556 ms |
57616 KB |
Output is correct |
31 |
Correct |
664 ms |
66912 KB |
Output is correct |
32 |
Correct |
48 ms |
26740 KB |
Output is correct |
33 |
Correct |
292 ms |
37576 KB |
Output is correct |
34 |
Correct |
77 ms |
27792 KB |
Output is correct |
35 |
Correct |
27 ms |
25344 KB |
Output is correct |
36 |
Correct |
35 ms |
26744 KB |
Output is correct |
37 |
Correct |
51 ms |
23808 KB |
Output is correct |