#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int rd(){
int x=0,w=1;
char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
int maxn=5000;
vector<set<int>> st(maxn);
void solve(){
int n,q; cin>>n>>q;
for(int i=1;i<=n;i++){
st[i].insert(i);
}
for(int i=0;i<n+q-1;i++){
char x; cin>>x;
if(x=='C'){
int v; cin>>v;
int cnt=0;
for(int j=1;j<=n;j++){
if(st[j].find(v)!=st[j].end()) cnt++;
}
cout<<cnt<<'\n';
}
else if(x=='Q'){
int u,v; cin>>u>>v;
auto pos=st[u].find(v);
if(pos==st[u].end()) cout<<"no\n";
else cout<<"yes\n";
}
else{
int u,v; cin>>u>>v;
for(auto&p:st[u]) st[v].insert(p);
for(auto&p:st[v]) st[u].insert(p);
}
}
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tt=1; //cin>>tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
852 KB |
Output is correct |
2 |
Correct |
30 ms |
2172 KB |
Output is correct |
3 |
Correct |
233 ms |
47704 KB |
Output is correct |
4 |
Correct |
28 ms |
1868 KB |
Output is correct |
5 |
Correct |
27 ms |
1712 KB |
Output is correct |
6 |
Correct |
1811 ms |
377012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
852 KB |
Output is correct |
2 |
Correct |
30 ms |
2172 KB |
Output is correct |
3 |
Correct |
233 ms |
47704 KB |
Output is correct |
4 |
Correct |
28 ms |
1868 KB |
Output is correct |
5 |
Correct |
27 ms |
1712 KB |
Output is correct |
6 |
Correct |
1811 ms |
377012 KB |
Output is correct |
7 |
Correct |
23 ms |
928 KB |
Output is correct |
8 |
Correct |
3077 ms |
2092 KB |
Output is correct |
9 |
Execution timed out |
3562 ms |
20900 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
960 KB |
Output is correct |
2 |
Runtime error |
1 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
960 KB |
Output is correct |
2 |
Runtime error |
1 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
896 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
896 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
928 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
928 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
916 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
916 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
852 KB |
Output is correct |
2 |
Correct |
30 ms |
2228 KB |
Output is correct |
3 |
Correct |
252 ms |
47848 KB |
Output is correct |
4 |
Correct |
28 ms |
1904 KB |
Output is correct |
5 |
Correct |
28 ms |
1732 KB |
Output is correct |
6 |
Correct |
1777 ms |
377080 KB |
Output is correct |
7 |
Correct |
19 ms |
980 KB |
Output is correct |
8 |
Runtime error |
1 ms |
1364 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
852 KB |
Output is correct |
2 |
Correct |
30 ms |
2228 KB |
Output is correct |
3 |
Correct |
252 ms |
47848 KB |
Output is correct |
4 |
Correct |
28 ms |
1904 KB |
Output is correct |
5 |
Correct |
28 ms |
1732 KB |
Output is correct |
6 |
Correct |
1777 ms |
377080 KB |
Output is correct |
7 |
Correct |
19 ms |
980 KB |
Output is correct |
8 |
Runtime error |
1 ms |
1364 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |