#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
void solve() {
int n,q; cin>>n>>q;
vector<set<int>> a(n+1);
forn(i,n) a[i+1].insert(i+1);
forn(Q,n-1+q) {
char c;
cin>>c;
if (c=='S') {
int u,v; cin>>u>>v;
for (auto x:a[u]) a[v].insert(x);
for (auto x:a[v]) a[u].insert(x);
} else if (c=='Q') {
int u,x; cin>>u>>x;
cout << (a[u].count(x)?"yes\n":"no\n");
} else {
int x; cin>>x;
int ans=0;
forn(i,n) ans+=a[i+1].count(x);
cout<<ans<<'\n';
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Output is correct |
2 |
Correct |
32 ms |
2672 KB |
Output is correct |
3 |
Correct |
238 ms |
48208 KB |
Output is correct |
4 |
Correct |
29 ms |
2380 KB |
Output is correct |
5 |
Correct |
28 ms |
2104 KB |
Output is correct |
6 |
Correct |
1789 ms |
377172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Output is correct |
2 |
Correct |
32 ms |
2672 KB |
Output is correct |
3 |
Correct |
238 ms |
48208 KB |
Output is correct |
4 |
Correct |
29 ms |
2380 KB |
Output is correct |
5 |
Correct |
28 ms |
2104 KB |
Output is correct |
6 |
Correct |
1789 ms |
377172 KB |
Output is correct |
7 |
Correct |
22 ms |
852 KB |
Output is correct |
8 |
Correct |
2978 ms |
3312 KB |
Output is correct |
9 |
Execution timed out |
3568 ms |
21092 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
716 KB |
Output is correct |
2 |
Runtime error |
2090 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
716 KB |
Output is correct |
2 |
Runtime error |
2090 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
572 KB |
Output is correct |
2 |
Correct |
174 ms |
31856 KB |
Output is correct |
3 |
Correct |
175 ms |
32052 KB |
Output is correct |
4 |
Runtime error |
1217 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
572 KB |
Output is correct |
2 |
Correct |
174 ms |
31856 KB |
Output is correct |
3 |
Correct |
175 ms |
32052 KB |
Output is correct |
4 |
Runtime error |
1217 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
596 KB |
Output is correct |
2 |
Runtime error |
2654 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
596 KB |
Output is correct |
2 |
Runtime error |
2654 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
588 KB |
Output is correct |
2 |
Correct |
187 ms |
31640 KB |
Output is correct |
3 |
Correct |
176 ms |
31564 KB |
Output is correct |
4 |
Runtime error |
1246 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
588 KB |
Output is correct |
2 |
Correct |
187 ms |
31640 KB |
Output is correct |
3 |
Correct |
176 ms |
31564 KB |
Output is correct |
4 |
Runtime error |
1246 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
688 KB |
Output is correct |
2 |
Correct |
31 ms |
2160 KB |
Output is correct |
3 |
Correct |
257 ms |
47720 KB |
Output is correct |
4 |
Correct |
28 ms |
1796 KB |
Output is correct |
5 |
Correct |
28 ms |
1684 KB |
Output is correct |
6 |
Correct |
1814 ms |
377100 KB |
Output is correct |
7 |
Correct |
19 ms |
704 KB |
Output is correct |
8 |
Runtime error |
2165 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
688 KB |
Output is correct |
2 |
Correct |
31 ms |
2160 KB |
Output is correct |
3 |
Correct |
257 ms |
47720 KB |
Output is correct |
4 |
Correct |
28 ms |
1796 KB |
Output is correct |
5 |
Correct |
28 ms |
1684 KB |
Output is correct |
6 |
Correct |
1814 ms |
377100 KB |
Output is correct |
7 |
Correct |
19 ms |
704 KB |
Output is correct |
8 |
Runtime error |
2165 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |