#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]) A = cmp[A], cmp[A] = cmp[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) {
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:41: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++;
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
167 ms |
24960 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
20 ms |
25600 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
63 ms |
23932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
25600 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23936 KB |
Output is correct |
4 |
Correct |
22 ms |
24552 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
549 ms |
57572 KB |
Output is correct |
7 |
Correct |
623 ms |
66656 KB |
Output is correct |
8 |
Correct |
27 ms |
25472 KB |
Output is correct |
9 |
Correct |
39 ms |
26752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Incorrect |
21 ms |
24064 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Incorrect |
21 ms |
24064 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23936 KB |
Output is correct |
4 |
Correct |
19 ms |
23936 KB |
Output is correct |
5 |
Incorrect |
21 ms |
24064 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |