#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
int n,q;
cin>>n>>q;
if(n <= 4000){
vector<vector<bool>> vis(n+1,vector<bool>(n+1));
for(int i=1;i<=n;i++) vis[i][i] = 1;
vector<int> cnt(n+1,1);
for(int qq=0;qq<n+q-1;qq++){
char c;
int a,b;
cin>>c>>a;
if(c != 'C') cin>>b;
if(c == 'S'){
for(int j=1;j<=n;j++){
cnt[j] += vis[a][j] ^ vis[b][j];
vis[a][j] = vis[a][j] | vis[b][j];
}
vis[b] = vis[a];
}
else if(c == 'C') cout<<cnt[a]<<endl;
else cout<<(vis[a][b] ? "yes" : "no")<<endl;
}
}
else {
vector<bool> vis(n+1);
vis[1] = 1;
vector<int> idx(n+1);
int cnt = 1;
idx[1] = 0;
for(int qq=0;qq<n+q-1;qq++){
char c;
int a,b;
cin>>c>>a;
if(c != 'C') cin>>b;
if(c == 'S'){
vis[max(a,b)] = 1;
idx[max(a,b)] = cnt;
cnt ++;
}
else if(c == 'C') cout<<cnt - idx[a] + (a != 1)<<endl;
else {
if(a == b) cout<<"yes"<<endl;
else {
if(min(a,b) == 1 && vis[a] && vis[b]) cout<<"yes"<<endl;
else if(vis[a] && vis[b] && idx[a] > idx[b]) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
600 KB |
Output is correct |
2 |
Correct |
84 ms |
2816 KB |
Output is correct |
3 |
Correct |
83 ms |
2876 KB |
Output is correct |
4 |
Correct |
82 ms |
2896 KB |
Output is correct |
5 |
Correct |
93 ms |
2940 KB |
Output is correct |
6 |
Correct |
81 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
600 KB |
Output is correct |
2 |
Correct |
84 ms |
2816 KB |
Output is correct |
3 |
Correct |
83 ms |
2876 KB |
Output is correct |
4 |
Correct |
82 ms |
2896 KB |
Output is correct |
5 |
Correct |
93 ms |
2940 KB |
Output is correct |
6 |
Correct |
81 ms |
2900 KB |
Output is correct |
7 |
Correct |
15 ms |
600 KB |
Output is correct |
8 |
Correct |
81 ms |
2724 KB |
Output is correct |
9 |
Correct |
80 ms |
2900 KB |
Output is correct |
10 |
Correct |
81 ms |
2708 KB |
Output is correct |
11 |
Correct |
80 ms |
2880 KB |
Output is correct |
12 |
Correct |
81 ms |
2940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
860 KB |
Output is correct |
2 |
Correct |
35 ms |
1116 KB |
Output is correct |
3 |
Correct |
36 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
860 KB |
Output is correct |
2 |
Correct |
35 ms |
1116 KB |
Output is correct |
3 |
Correct |
36 ms |
1372 KB |
Output is correct |
4 |
Correct |
16 ms |
600 KB |
Output is correct |
5 |
Incorrect |
35 ms |
1372 KB |
Extra information in the output file |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
748 KB |
Output is correct |
2 |
Incorrect |
38 ms |
1276 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
748 KB |
Output is correct |
2 |
Incorrect |
38 ms |
1276 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
604 KB |
Output is correct |
2 |
Incorrect |
36 ms |
1104 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
604 KB |
Output is correct |
2 |
Incorrect |
36 ms |
1104 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
600 KB |
Output is correct |
2 |
Incorrect |
39 ms |
1152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
600 KB |
Output is correct |
2 |
Incorrect |
39 ms |
1152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
604 KB |
Output is correct |
2 |
Correct |
89 ms |
2956 KB |
Output is correct |
3 |
Correct |
82 ms |
2900 KB |
Output is correct |
4 |
Correct |
102 ms |
2812 KB |
Output is correct |
5 |
Correct |
84 ms |
2888 KB |
Output is correct |
6 |
Correct |
82 ms |
2900 KB |
Output is correct |
7 |
Correct |
15 ms |
856 KB |
Output is correct |
8 |
Correct |
39 ms |
1304 KB |
Output is correct |
9 |
Correct |
35 ms |
1256 KB |
Output is correct |
10 |
Correct |
15 ms |
600 KB |
Output is correct |
11 |
Incorrect |
37 ms |
1116 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
604 KB |
Output is correct |
2 |
Correct |
89 ms |
2956 KB |
Output is correct |
3 |
Correct |
82 ms |
2900 KB |
Output is correct |
4 |
Correct |
102 ms |
2812 KB |
Output is correct |
5 |
Correct |
84 ms |
2888 KB |
Output is correct |
6 |
Correct |
82 ms |
2900 KB |
Output is correct |
7 |
Correct |
15 ms |
856 KB |
Output is correct |
8 |
Correct |
39 ms |
1304 KB |
Output is correct |
9 |
Correct |
35 ms |
1256 KB |
Output is correct |
10 |
Correct |
15 ms |
600 KB |
Output is correct |
11 |
Incorrect |
37 ms |
1116 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |