#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("talent.in");
ofstream fout("talent.out");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 5e5 + 3;
int n, m;
vt<pii>edge;
vt<int>g[mxn + 1];
bool ok[mxn + 1], ans[mxn + 1];
struct DSU{
int p[mxn + 1];
void init(){
for(int i = 1; i <= n; i++)p[i] = -1;
}
int fp(int a){
if(p[a] < 0)return(a);
return(p[a] = fp(p[a]));
}
void unon(int a, int b){
a = fp(a); b = fp(b);
if(a == b)return;
if(-p[a] < -p[b])swap(a, b);
p[a] += p[b]; p[b] = a;
return;
}
};
DSU dsu;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
dsu.init();
forr(i, 0, m){
int u, v; cin >> u >> v;
char c; cin >> c;
if(c == 'A'){
edge.pb({u, v});
}else{
dsu.unon(u, v);
}
}
int cnt = 0;
for(int i = 1; i <= n; i++){
if(dsu.p[i] < 0)cnt++;
}
for(auto [u, v]: edge){
u = dsu.fp(u); v = dsu.fp(v);
if(u != v){
g[u].pb(v); g[v].pb(u);
}
//cout << u << ' ' << v << " ";
}
for(int i = 1; i <= n; i++){
if(dsu.p[i] < 0){
int curr =0;
for(auto j: g[i]){
if(!ok[j]){
ok[j] = true; curr++;
}
}
ans[i] = ((curr + 1) == cnt);
for(auto j: g[i])ok[j] = false;
}
}
int res =0;
for(int i = 1; i <= n; i++){
res += ans[dsu.fp(i)];
}
cout << res;
return 0;
}
Compilation message
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
61 | for(auto [u, v]: edge){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
13224 KB |
Output is correct |
2 |
Correct |
9 ms |
12012 KB |
Output is correct |
3 |
Correct |
8 ms |
12088 KB |
Output is correct |
4 |
Correct |
11 ms |
14368 KB |
Output is correct |
5 |
Correct |
7 ms |
12116 KB |
Output is correct |
6 |
Correct |
39 ms |
14384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14368 KB |
Output is correct |
2 |
Correct |
7 ms |
12116 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12116 KB |
Output is correct |
5 |
Correct |
9 ms |
12244 KB |
Output is correct |
6 |
Correct |
94 ms |
19000 KB |
Output is correct |
7 |
Correct |
192 ms |
31948 KB |
Output is correct |
8 |
Correct |
10 ms |
12756 KB |
Output is correct |
9 |
Correct |
14 ms |
12888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12012 KB |
Output is correct |
2 |
Correct |
8 ms |
12088 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12116 KB |
Output is correct |
5 |
Correct |
9 ms |
12244 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12180 KB |
Output is correct |
8 |
Correct |
7 ms |
12116 KB |
Output is correct |
9 |
Correct |
8 ms |
12092 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
8 ms |
12244 KB |
Output is correct |
15 |
Correct |
9 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12112 KB |
Output is correct |
17 |
Correct |
7 ms |
11988 KB |
Output is correct |
18 |
Correct |
8 ms |
12092 KB |
Output is correct |
19 |
Correct |
7 ms |
12116 KB |
Output is correct |
20 |
Correct |
6 ms |
12096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12180 KB |
Output is correct |
3 |
Correct |
7 ms |
12116 KB |
Output is correct |
4 |
Correct |
8 ms |
12092 KB |
Output is correct |
5 |
Correct |
8 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12116 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
8 ms |
12244 KB |
Output is correct |
10 |
Correct |
9 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
12112 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12092 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
6 ms |
12096 KB |
Output is correct |
16 |
Correct |
9 ms |
12012 KB |
Output is correct |
17 |
Correct |
8 ms |
12088 KB |
Output is correct |
18 |
Correct |
7 ms |
11988 KB |
Output is correct |
19 |
Correct |
7 ms |
12116 KB |
Output is correct |
20 |
Correct |
9 ms |
12244 KB |
Output is correct |
21 |
Correct |
7 ms |
12116 KB |
Output is correct |
22 |
Correct |
10 ms |
12756 KB |
Output is correct |
23 |
Correct |
14 ms |
12888 KB |
Output is correct |
24 |
Correct |
39 ms |
14384 KB |
Output is correct |
25 |
Correct |
12 ms |
13016 KB |
Output is correct |
26 |
Correct |
85 ms |
23200 KB |
Output is correct |
27 |
Correct |
34 ms |
16456 KB |
Output is correct |
28 |
Correct |
48 ms |
18072 KB |
Output is correct |
29 |
Correct |
33 ms |
15576 KB |
Output is correct |
30 |
Correct |
45 ms |
16824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12180 KB |
Output is correct |
3 |
Correct |
7 ms |
12116 KB |
Output is correct |
4 |
Correct |
8 ms |
12092 KB |
Output is correct |
5 |
Correct |
8 ms |
12244 KB |
Output is correct |
6 |
Correct |
7 ms |
12116 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
8 ms |
12244 KB |
Output is correct |
10 |
Correct |
9 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
12112 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12092 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
6 ms |
12096 KB |
Output is correct |
16 |
Correct |
12 ms |
13016 KB |
Output is correct |
17 |
Correct |
85 ms |
23200 KB |
Output is correct |
18 |
Correct |
34 ms |
16456 KB |
Output is correct |
19 |
Correct |
48 ms |
18072 KB |
Output is correct |
20 |
Correct |
33 ms |
15576 KB |
Output is correct |
21 |
Correct |
45 ms |
16824 KB |
Output is correct |
22 |
Correct |
106 ms |
13224 KB |
Output is correct |
23 |
Correct |
9 ms |
12012 KB |
Output is correct |
24 |
Correct |
8 ms |
12088 KB |
Output is correct |
25 |
Correct |
11 ms |
14368 KB |
Output is correct |
26 |
Correct |
7 ms |
11988 KB |
Output is correct |
27 |
Correct |
7 ms |
12116 KB |
Output is correct |
28 |
Correct |
9 ms |
12244 KB |
Output is correct |
29 |
Correct |
7 ms |
12116 KB |
Output is correct |
30 |
Correct |
94 ms |
19000 KB |
Output is correct |
31 |
Correct |
192 ms |
31948 KB |
Output is correct |
32 |
Correct |
10 ms |
12756 KB |
Output is correct |
33 |
Correct |
14 ms |
12888 KB |
Output is correct |
34 |
Correct |
39 ms |
14384 KB |
Output is correct |
35 |
Correct |
20 ms |
13836 KB |
Output is correct |
36 |
Correct |
98 ms |
25476 KB |
Output is correct |
37 |
Correct |
50 ms |
16204 KB |
Output is correct |