#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
int cnt[n+1] = {};
vi data[n+1];
rep (i,1,n) {
data[i].pb(i);
++cnt[i];
}
rep (q,1,n+k-1) {
char tp; cin >> tp;
if (tp=='S') {
int a, b; cin >> a >> b;
int x = data[b].size();
for (int el : data[a]) {
data[b].pb(el);
++cnt[el];
}
rep (i,0,x-1) {
data[a].pb(data[b][i]);
++cnt[data[b][i]];
}
}
else if (tp=='Q') {
int a, d; cin >> a >> d;
if (find(all(data[a]), d)!=data[a].end()) {
cout << "yes\n";
}
else {
cout << "no\n";
}
}
else {
int d; cin >> d;
cout << cnt[d] << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1472 KB |
Output is correct |
2 |
Correct |
26 ms |
2344 KB |
Output is correct |
3 |
Correct |
52 ms |
8008 KB |
Output is correct |
4 |
Correct |
26 ms |
2364 KB |
Output is correct |
5 |
Correct |
28 ms |
2256 KB |
Output is correct |
6 |
Correct |
194 ms |
42428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1472 KB |
Output is correct |
2 |
Correct |
26 ms |
2344 KB |
Output is correct |
3 |
Correct |
52 ms |
8008 KB |
Output is correct |
4 |
Correct |
26 ms |
2364 KB |
Output is correct |
5 |
Correct |
28 ms |
2256 KB |
Output is correct |
6 |
Correct |
194 ms |
42428 KB |
Output is correct |
7 |
Correct |
18 ms |
1484 KB |
Output is correct |
8 |
Correct |
23 ms |
2040 KB |
Output is correct |
9 |
Correct |
56 ms |
9388 KB |
Output is correct |
10 |
Correct |
27 ms |
2032 KB |
Output is correct |
11 |
Correct |
24 ms |
1988 KB |
Output is correct |
12 |
Correct |
158 ms |
42212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1556 KB |
Output is correct |
2 |
Runtime error |
1558 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1556 KB |
Output is correct |
2 |
Runtime error |
1558 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1492 KB |
Output is correct |
2 |
Correct |
107 ms |
11932 KB |
Output is correct |
3 |
Correct |
113 ms |
11996 KB |
Output is correct |
4 |
Runtime error |
1753 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1492 KB |
Output is correct |
2 |
Correct |
107 ms |
11932 KB |
Output is correct |
3 |
Correct |
113 ms |
11996 KB |
Output is correct |
4 |
Runtime error |
1753 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1516 KB |
Output is correct |
2 |
Runtime error |
1230 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1516 KB |
Output is correct |
2 |
Runtime error |
1230 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1428 KB |
Output is correct |
2 |
Correct |
114 ms |
12044 KB |
Output is correct |
3 |
Correct |
112 ms |
12000 KB |
Output is correct |
4 |
Runtime error |
1723 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1428 KB |
Output is correct |
2 |
Correct |
114 ms |
12044 KB |
Output is correct |
3 |
Correct |
112 ms |
12000 KB |
Output is correct |
4 |
Runtime error |
1723 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1544 KB |
Output is correct |
2 |
Correct |
26 ms |
2380 KB |
Output is correct |
3 |
Correct |
57 ms |
7940 KB |
Output is correct |
4 |
Correct |
27 ms |
2292 KB |
Output is correct |
5 |
Correct |
27 ms |
2304 KB |
Output is correct |
6 |
Correct |
192 ms |
42472 KB |
Output is correct |
7 |
Correct |
19 ms |
1468 KB |
Output is correct |
8 |
Runtime error |
1498 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1544 KB |
Output is correct |
2 |
Correct |
26 ms |
2380 KB |
Output is correct |
3 |
Correct |
57 ms |
7940 KB |
Output is correct |
4 |
Correct |
27 ms |
2292 KB |
Output is correct |
5 |
Correct |
27 ms |
2304 KB |
Output is correct |
6 |
Correct |
192 ms |
42472 KB |
Output is correct |
7 |
Correct |
19 ms |
1468 KB |
Output is correct |
8 |
Runtime error |
1498 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |