#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5 + 5;
struct DSU{
vector<int>par;
int comps;
DSU(int n){
par.assign(n + 1, -1);
comps = n;
}
int FindRep(int u){
if(par[u] < 0)return u;
return par[u] = FindRep(par[u]);
}
void Union(int u, int v){
u = FindRep(u);
v = FindRep(v);
if(u == v)return;
if(par[u] > par[v])swap(u, v);
par[u] += par[v];
par[v] = u;
comps--;
}
};
vector<int> G[mxN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int cnt = 0;
/// A - bus, T - train
DSU dsu(n);
for(int i = 0;i < m;++i){
int u, v;
char c;
cin >> u >> v >> c;
cnt += (c == 'A');
dsu.Union(u, v);
G[u].push_back(v);
G[v].push_back(u);
}
if(dsu.comps != 1){
cout << 0 << '\n';
}
else if(cnt == 0){
cout << n << '\n';
}
int cnt2 = 0;
for(int i = 1;i <= n;++i){
cnt2 += ((int)G[i].size() == n - 1);
}
cout << cnt2 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
23916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
13916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
12144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
12144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
12144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |