#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int t, n;
vi a, b;
int main(){
int q;
cin>>n>>q;
q+=n-1;
set<int> a[n+1];
FOR(i,n+1){
a[i].insert(i);
}
int cnt[n+1];
FOR(i,n+1) cnt[i] = 1;
while(q--){
char s;
cin>>s;
if(s=='S'){
int x, y;
cin>>x>>y;
FOA(v, a[x]) a[y].insert(v);
FOA(v, a[y]) a[x].insert(v);
FOA(v,a[x]) cnt[v]++;
}
else if(s=='Q'){
int x, y;
cin>>x>>y;
if(a[x].count(y)) cout<<"yes\n";
else cout<<"no\n";
}
else{
int x;
cin>>x;
cout<<cnt[x]<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
688 KB |
Output is correct |
2 |
Correct |
298 ms |
2128 KB |
Output is correct |
3 |
Correct |
599 ms |
47836 KB |
Output is correct |
4 |
Correct |
276 ms |
1756 KB |
Output is correct |
5 |
Correct |
277 ms |
1756 KB |
Output is correct |
6 |
Correct |
2731 ms |
376848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
688 KB |
Output is correct |
2 |
Correct |
298 ms |
2128 KB |
Output is correct |
3 |
Correct |
599 ms |
47836 KB |
Output is correct |
4 |
Correct |
276 ms |
1756 KB |
Output is correct |
5 |
Correct |
277 ms |
1756 KB |
Output is correct |
6 |
Correct |
2731 ms |
376848 KB |
Output is correct |
7 |
Correct |
260 ms |
636 KB |
Output is correct |
8 |
Correct |
278 ms |
3292 KB |
Output is correct |
9 |
Correct |
569 ms |
60996 KB |
Output is correct |
10 |
Correct |
272 ms |
2872 KB |
Output is correct |
11 |
Correct |
264 ms |
2620 KB |
Output is correct |
12 |
Correct |
2699 ms |
377996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
692 KB |
Output is correct |
2 |
Runtime error |
3105 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
692 KB |
Output is correct |
2 |
Runtime error |
3105 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
576 KB |
Output is correct |
2 |
Correct |
519 ms |
31868 KB |
Output is correct |
3 |
Correct |
521 ms |
31812 KB |
Output is correct |
4 |
Runtime error |
1766 ms |
524292 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
576 KB |
Output is correct |
2 |
Correct |
519 ms |
31868 KB |
Output is correct |
3 |
Correct |
521 ms |
31812 KB |
Output is correct |
4 |
Runtime error |
1766 ms |
524292 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
524 KB |
Output is correct |
2 |
Execution timed out |
3600 ms |
517904 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
524 KB |
Output is correct |
2 |
Execution timed out |
3600 ms |
517904 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
756 KB |
Output is correct |
2 |
Correct |
559 ms |
31780 KB |
Output is correct |
3 |
Correct |
514 ms |
31712 KB |
Output is correct |
4 |
Runtime error |
1795 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
756 KB |
Output is correct |
2 |
Correct |
559 ms |
31780 KB |
Output is correct |
3 |
Correct |
514 ms |
31712 KB |
Output is correct |
4 |
Runtime error |
1795 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
644 KB |
Output is correct |
2 |
Correct |
355 ms |
2112 KB |
Output is correct |
3 |
Correct |
550 ms |
47648 KB |
Output is correct |
4 |
Correct |
297 ms |
1768 KB |
Output is correct |
5 |
Correct |
275 ms |
1636 KB |
Output is correct |
6 |
Correct |
2686 ms |
376932 KB |
Output is correct |
7 |
Correct |
265 ms |
708 KB |
Output is correct |
8 |
Runtime error |
3155 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
644 KB |
Output is correct |
2 |
Correct |
355 ms |
2112 KB |
Output is correct |
3 |
Correct |
550 ms |
47648 KB |
Output is correct |
4 |
Correct |
297 ms |
1768 KB |
Output is correct |
5 |
Correct |
275 ms |
1636 KB |
Output is correct |
6 |
Correct |
2686 ms |
376932 KB |
Output is correct |
7 |
Correct |
265 ms |
708 KB |
Output is correct |
8 |
Runtime error |
3155 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |