/*
* Author: fuad720
* Time: 2023-07-04 18:11
*/
// =========== Template ========== //
#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#else
#include "/home/fuad/cp/all.h"
#endif
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using omset =
tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ull = unsigned long long;
using ld=long double;
using lll = __int128_t;
using ulll = __uint128_t;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) FOR(i,0,b)
#define FORN(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) FORN(i,0,b)
#define mkp make_pair
#define pb push_back
#define ep emplace_back
#define ins insert
#define ff first
#define ss second
#define bg begin()
#define ed end()
#define sz(x) (int)x.size()
#define all(x) (x).bg,(x).ed
#define FIO ios_base::sync_with_stdio(0);\
cin.tie(0);
template<class t> using vc=vector<t>;;
template<class t> using vvc=vc<vc<t>>;
template<class F, class S> using pr=pair<F,S>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi= vc<int>;
using vll= vc<ll>;
#define mset multiset
#define umap unordered_map
#define pqueue priority_queue
int nxt() {
int x;
cin >> x;
return x;
}
ll nxtll() {
ll x;
cin >> x;
return x;
}
#ifdef LOCAL
#include "/home/fuad/cp/dbg.h"
#else
#define dbg(x...)
#endif
const ll INFL=(ll)1e18;
const int INF=(ll)2e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count());
// =========== Solution ========== //
const int N=120010;
bitset<N> B[N];
string s;
int n, k;
void solve() {
cin >> n >> k;
k+=n-1;
for(int i = 0;i<n;i++)B[i][i]=1;
while(k--) {
cin >> s;
if(s[0]=='S') {
int a, b;
cin >> a >> b;
a--,b--;
B[a]|=B[b];
B[b]|=B[a];
}
else if(s[0]=='Q') {
int a, b;
cin >> a >> b;
a--,b--;
cout << (B[a][b]?"yes":"no") << "\n";
}
else {
int c;
cin >> c;
c--;
int cnt=0;
for(int i = 0;i<n;i++) {
cnt+=B[i][c];
}
cout << cnt << "\n";
}
}
}
signed main () {
FIO;
int t=1;
while(t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1308 KB |
Output is correct |
2 |
Correct |
68 ms |
59356 KB |
Output is correct |
3 |
Correct |
77 ms |
59420 KB |
Output is correct |
4 |
Correct |
67 ms |
59328 KB |
Output is correct |
5 |
Correct |
67 ms |
59364 KB |
Output is correct |
6 |
Correct |
62 ms |
59472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1308 KB |
Output is correct |
2 |
Correct |
68 ms |
59356 KB |
Output is correct |
3 |
Correct |
77 ms |
59420 KB |
Output is correct |
4 |
Correct |
67 ms |
59328 KB |
Output is correct |
5 |
Correct |
67 ms |
59364 KB |
Output is correct |
6 |
Correct |
62 ms |
59472 KB |
Output is correct |
7 |
Correct |
27 ms |
1364 KB |
Output is correct |
8 |
Correct |
1894 ms |
59680 KB |
Output is correct |
9 |
Correct |
2225 ms |
59732 KB |
Output is correct |
10 |
Correct |
2278 ms |
59616 KB |
Output is correct |
11 |
Correct |
2752 ms |
59560 KB |
Output is correct |
12 |
Correct |
2406 ms |
59776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1424 KB |
Output is correct |
2 |
Runtime error |
203 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1424 KB |
Output is correct |
2 |
Runtime error |
203 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1288 KB |
Output is correct |
2 |
Runtime error |
162 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1288 KB |
Output is correct |
2 |
Runtime error |
162 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1584 KB |
Output is correct |
2 |
Runtime error |
194 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1584 KB |
Output is correct |
2 |
Runtime error |
194 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1656 KB |
Output is correct |
2 |
Runtime error |
160 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1656 KB |
Output is correct |
2 |
Runtime error |
160 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1648 KB |
Output is correct |
2 |
Correct |
72 ms |
59512 KB |
Output is correct |
3 |
Correct |
66 ms |
59496 KB |
Output is correct |
4 |
Correct |
97 ms |
59512 KB |
Output is correct |
5 |
Correct |
68 ms |
59468 KB |
Output is correct |
6 |
Correct |
67 ms |
59496 KB |
Output is correct |
7 |
Correct |
21 ms |
1520 KB |
Output is correct |
8 |
Runtime error |
201 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1648 KB |
Output is correct |
2 |
Correct |
72 ms |
59512 KB |
Output is correct |
3 |
Correct |
66 ms |
59496 KB |
Output is correct |
4 |
Correct |
97 ms |
59512 KB |
Output is correct |
5 |
Correct |
68 ms |
59468 KB |
Output is correct |
6 |
Correct |
67 ms |
59496 KB |
Output is correct |
7 |
Correct |
21 ms |
1520 KB |
Output is correct |
8 |
Runtime error |
201 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |