제출 #79871

#제출 시각아이디문제언어결과실행 시간메모리
79871win11905Pipes (BOI13_pipes)C++11
22.80 / 100
1083 ms132096 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; int n, m, s[N], t[N]; int A[N], deg[N]; int ans[N]; set<int> g[N]; void answer() { for(int i = 0; i < m; ++i) printf("%d\n", ans[i]); exit(0); } void solve() { queue<int> Q; for(int i = 1; i <= n; ++i) if(deg[i] == 1) Q.emplace(i); while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int x : g[u]) { int v = u ^ s[x] ^ t[x]; g[v].erase(x), g[u].clear(); A[v] -= A[u]; ans[x] = A[u] << 1; if(g[v].size() == 1) Q.emplace(v); } } } int cnt = 0; void dfs(int u, int p) { static int idx = 0; static int sum = 0; idx++; if(idx & 1) sum += A[u]; else sum -= A[u]; for(auto i : g[u]) { int v = u ^ s[i] ^ t[i]; if(v != p) { if(cnt == sum) { ans[i] = sum; A[u] -= sum / 2, A[v] -= sum / 2; g[u].erase(i), g[v].erase(i); return; } dfs(v, u); } } } int main() { scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", A+i); for(int i = 0; i < m; ++i) { scanf("%d %d", s+i, t+i); g[s[i]].emplace(i), g[t[i]].emplace(i); deg[s[i]]++, deg[t[i]]++; } if(n < m) return puts("0"), 0; solve(); if(n == m+1) answer(); for(int i = 1; i <= n; ++i) if(g[i].size()) cnt++; if(cnt % 2 == 0) return puts("0"), 0; for(int i = 1; i <= n; ++i) { if(g[i].size()) dfs(i, i); break; } solve(); answer(); }

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

pipes.cpp: In function 'int main()':
pipes.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:57:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; ++i) scanf("%d", A+i);
                                 ~~~~~^~~~~~~~~~~
pipes.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", s+i, t+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...