이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5 + 2;
const int LG = 18;
int vst[maxn],tout[maxn],h[maxn],active[maxn],val[maxn], valid[maxn];
int pa[maxn][LG + 2];
pii e[maxn];
vector<pii> a[maxn];
int n,m,q,T;
void dfs(int u, int va) {
vst[u] = 1;
val[u] = va;
for (pii tmp : a[u]) {
int v,id; tie(v,id) = tmp;
if (active[id]) {
if (vst[v]==0) {
dfs(v,va);
}
}
}
}
void solve() {
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) val[i]= 1;
for (int i = 1; i < n; i++) {
int x,y; cin >> x >> y;
a[x].push_back({y,i});
a[y].push_back({x,i});
e[i] = {x,y};
}
for (int i = 1; i <= m; i++) {
int id; cin >> id;
if (!active[id]) {
int u,v; tie(u,v) = e[id];
int du = val[v] - valid[id];
int dv = val[u] - valid[id];
memset(vst,0,sizeof(int)*(n+2));
dfs(u,val[u] + du);
memset(vst,0,sizeof(int)*(n+2));
dfs(v,val[v] + dv);
valid[id] = val[v];
assert(val[v]==val[u]);
}
active[id] = !active[id];
}
for (int i = 1; i <= q; i++) {
int x; cin >> x;
cout << val[x] << '\n';
}
}
void file(string name) {
if (fopen((name + ".inp").c_str(), "r")) {
freopen((name + ".inp").c_str(), "r", stdin);
freopen((name + ".ans").c_str(), "w", stdout);
}
}
signed main() {
file("B");
cin.tie(0) -> sync_with_stdio(0);
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
synchronization.cpp: In function 'void file(std::string)':
synchronization.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen((name + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen((name + ".ans").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |