이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
const int maxq = 2e5 + 10;
int n, q, N, h[maxn], cnt[maxn], ans[maxq];
int mark[maxq];
vector<pii> g[maxn];
vector<pii> Q2[maxn];
vector<pair<pii,int>> 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;
int tmp = 0;
for (int i = 1; i < N; i++){
char t; cin >> t;
if (t == 'S'){
tmp++;
int u, v; cin >> u >> v;
g[u].push_back({v, tmp});
g[v].push_back({u, tmp});
}
else if (t == 'Q'){
int x, y; cin >> x >> y;
Q1[y].push_back({{tmp, x}, i});
mark[i] = 1;
}
else{
int x; cin >> x;
Q2[x].push_back({tmp, 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+1;
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 [x, t]: Q1[i]){
if (h[x.S] <= x.F) ans[t] = 1;
}
for (auto [x, t]: Q2[i]){
ans[t] = cnt[x];
}
}
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;
}
# | 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... |