This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second
const int maxn = 1e4 + 10;
int n, q, N, h[maxn], cnt[maxn], ans[maxn];
int mark[maxn];
vector<pii> g[maxn];
vector<int> Q2[maxn];
vector<pii> Q1[maxn];
void dfs(int v, int p = -1){
for (auto [u, w]: g[v]){
if (w > h[v]){
h[u] = w;
dfs(u, v);
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
N = n + q;
for (int i = 1; i < N; i++){
char t; cin >> t;
if (t == 'S'){
int u, v; cin >> u >> v;
g[u].push_back({v, i});
g[v].push_back({u, i});
}
else if (t == 'Q'){
int x, y; cin >> x >> y;
Q1[y].push_back({i, x});
mark[i] = 1;
}
else{
int x; cin >> x;
Q2[x].push_back(i);
mark[i] = 2;
}
}
for (int i = 1; i <= n; i++){
memset(cnt, 0, sizeof cnt);
for (int j = 1; j <= n; j++) h[j] = N;
h[i] = 0;
dfs(i);
for (int j = 1; j <= n; j++){
cnt[h[j]]++;
}
for (int j = 1; j <= N; j++) cnt[j] += cnt[j-1];
for (auto [t, x]: Q1[i]){
if (h[x] <= t) ans[t] = 1;
}
for (auto t: Q2[i]){
ans[t] = cnt[t];
}
}
for (int i = 1; i < N; i++){
if (mark[i] == 1) cout << (ans[i]? "yes\n": "no\n");
else if (mark[i] == 2) cout << ans[i] << '\n';
}
return 0;
}
Compilation message (stderr)
servers.cpp: In function 'void dfs(int, int)':
servers.cpp:33:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | for (auto [u, w]: g[v]){
| ^
servers.cpp: In function 'int main()':
servers.cpp:76:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | for (auto [t, x]: Q1[i]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |