제출 #77285

#제출 시각아이디문제언어결과실행 시간메모리
77285tmwilliamlin168Pipes (BOI13_pipes)C++14
100 / 100
116 ms54500 KiB
#include <bits/stdc++.h> using namespace std; //are lls needed? #define ll long long const int mxN=1e5; int n, m, eu[mxN], ev[mxN], d[mxN], qu[mxN-1], qt, nx[mxN]; ll a[mxN], b[mxN]; vector<int> adj[mxN]; void fk() { cout << 0; exit(0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; if(m>n) fk(); for(int i=0; i<n; ++i) cin >> a[i]; for(int i=0; i<m; ++i) { cin >> eu[i] >> ev[i], --eu[i], --ev[i]; adj[eu[i]].push_back(i); adj[ev[i]].push_back(i); ++d[eu[i]]; ++d[ev[i]]; } for(int i=0; i<n; ++i) if(d[i]==1) qu[qt++]=i; for(int qh=0; qh<n-1; ++qh) { if(qh>=qt) { if((n^qh)&1^1) fk(); int u=-1, l=-1; while(!d[++u]); ll s1=0; for(int v=u, w, s2=1; v!=u||l==-1; l=nx[v], v=w, s2=-s2) { // cout << "h2 " << v << endl; for(int e : adj[v]) { nx[v]=e; w=v^eu[e]^ev[e]; if(d[w]&&e!=l) break; } s1+=s2*a[v]; // cout << s1 << " " << nx[v] << endl; } b[l]=s1; for(int v=u, w; nx[v]!=l; v^=eu[nx[v]]^ev[nx[v]]) b[nx[v]]=s1=2*a[v]-s1; a[0]=0; break; } int u=qu[qh]; // cout << "h1 " << u << endl; for(int e : adj[u]) { int v=u^eu[e]^ev[e]; if(!d[v]) continue; b[e]=2*a[u]; a[v]-=a[u]; if(--d[v]==1) qu[qt++]=v; break; } d[u]=0; } if(a[qu[n-1]]) fk(); for(int i=0; i<m; ++i) cout << b[i] << "\n"; }

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

pipes.cpp: In function 'int main()':
pipes.cpp:39:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    if((n^qh)&1^1)
       ~~~~~~^~
pipes.cpp:56:17: warning: unused variable 'w' [-Wunused-variable]
    for(int v=u, w; nx[v]!=l; v^=eu[nx[v]]^ev[nx[v]])
                 ^
pipes.cpp:44:27: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
    for(int v=u, w, s2=1; v!=u||l==-1; l=nx[v], v=w, s2=-s2) {
                          ~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...