#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 |
Incorrect |
17 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
856 KB |
Output is correct |
2 |
Correct |
42 ms |
1116 KB |
Output is correct |
3 |
Correct |
42 ms |
1328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
856 KB |
Output is correct |
2 |
Correct |
42 ms |
1116 KB |
Output is correct |
3 |
Correct |
42 ms |
1328 KB |
Output is correct |
4 |
Incorrect |
16 ms |
600 KB |
Extra information in the output file |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |