#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()
{
int tt=1; //cin>>tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
1908 KB |
Output is correct |
2 |
Correct |
209 ms |
3580 KB |
Output is correct |
3 |
Correct |
419 ms |
49104 KB |
Output is correct |
4 |
Correct |
235 ms |
3224 KB |
Output is correct |
5 |
Correct |
223 ms |
3076 KB |
Output is correct |
6 |
Correct |
1978 ms |
378336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
1908 KB |
Output is correct |
2 |
Correct |
209 ms |
3580 KB |
Output is correct |
3 |
Correct |
419 ms |
49104 KB |
Output is correct |
4 |
Correct |
235 ms |
3224 KB |
Output is correct |
5 |
Correct |
223 ms |
3076 KB |
Output is correct |
6 |
Correct |
1978 ms |
378336 KB |
Output is correct |
7 |
Correct |
220 ms |
1712 KB |
Output is correct |
8 |
Correct |
3128 ms |
3392 KB |
Output is correct |
9 |
Execution timed out |
3555 ms |
21132 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
1856 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 |
194 ms |
1856 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 |
191 ms |
1788 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 |
191 ms |
1788 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 |
218 ms |
1776 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 |
218 ms |
1776 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 |
194 ms |
1752 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1324 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
1752 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1324 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
1784 KB |
Output is correct |
2 |
Correct |
257 ms |
3620 KB |
Output is correct |
3 |
Correct |
429 ms |
48980 KB |
Output is correct |
4 |
Correct |
281 ms |
3284 KB |
Output is correct |
5 |
Correct |
272 ms |
3072 KB |
Output is correct |
6 |
Correct |
2087 ms |
378304 KB |
Output is correct |
7 |
Correct |
202 ms |
1836 KB |
Output is correct |
8 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
1784 KB |
Output is correct |
2 |
Correct |
257 ms |
3620 KB |
Output is correct |
3 |
Correct |
429 ms |
48980 KB |
Output is correct |
4 |
Correct |
281 ms |
3284 KB |
Output is correct |
5 |
Correct |
272 ms |
3072 KB |
Output is correct |
6 |
Correct |
2087 ms |
378304 KB |
Output is correct |
7 |
Correct |
202 ms |
1836 KB |
Output is correct |
8 |
Runtime error |
2 ms |
1364 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |