제출 #1119095

#제출 시각아이디문제언어결과실행 시간메모리
1119095kiethm07동기화 (JOI13_synchronization)C++11
0 / 100
8053 ms13384 KiB
#include <bits/stdc++.h> #define pii pair<int,int> #define pli pair<long long,int> #define plii pair<long long,pii> #define fi first #define se second #define vi vector<int> #define vii vector<pii> #define all(x) x.begin(),x.end() #define compact(x) x.erase(unique(all(x)),x.end()) #define pb(x) push_back(x) using namespace std; typedef long long ll; typedef long double ld; const int inf = 1e9; const ll linf = 1e16; const double PI = acos(-1); const int N = 1e5 + 5; struct edge{ int u,v,w; edge(){} edge(int a,int b,int c){ u = a,v = b,w = c; } }; edge e[N]; vector<int> a[N]; int n,m,q; int pa[N]; bool active[N]; int val[N]; void dfs(int u,int p){ for (int v : a[u]){ if (v == p) continue; pa[v] = u; dfs(v,u); } } int getNode(int u){ while(active[pa[u]]) u = pa[u]; return u; } void query(int id){ if (e[id].v == pa[e[id].u]) swap(e[id].u, e[id].v); int u = e[id].u; int v = e[id].v; int f = getNode(u); int tmp = val[f] + val[v] - e[id].w; val[f] = val[v] = e[id].w = tmp; active[v] ^= 1; } int main(){ #define TEXT "synchronization" cin.tie(0) -> sync_with_stdio(0); if (fopen(TEXT".inp","r")){ freopen(TEXT".inp","r",stdin); freopen(TEXT".ans","w",stdout); } cin >> n >> m >> q; for (int i = 1; i < n; i++){ int u,v; cin >> u >> v; a[u].push_back(v); a[v].push_back(u); e[i] = edge(u,v,0); } dfs(1,-1); while(m--){ int id; cin >> id; query(id); } while(q--){ int x; cin >> x; int f = getNode(x); cout << val[f] << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

synchronization.cpp: In function 'int main()':
synchronization.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(TEXT".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(TEXT".ans","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...