# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
111626 | 2019-05-15T20:49:52 Z | wilwxk | Pipes (BOI13_pipes) | C++11 | 582 ms | 132096 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+5; vector<int> g[MAXN], lista[MAXN]; vector<int> ncyc; ll v[MAXN], tenho[MAXN]; int gin[MAXN]; ll resp[MAXN], soma; int n, m; void poda() { queue<int> qu; for(int i=1; i<=n; i++) if(gin[i]==1) qu.push(i); while(!qu.empty()) { int cur=qu.front(); qu.pop(); gin[cur]=0; ncyc.push_back(cur); for(int i=0; i<g[cur].size(); i++) { int viz=g[cur][i]; int ind=lista[cur][i]; if(!gin[viz]) continue; gin[viz]--; if(gin[viz]<=1) qu.push(viz); resp[ind]=v[cur]-tenho[cur]; tenho[viz]+=resp[ind]; // printf("%d -> %d (%d, %lld)\n", cur, viz, ind, tenho[cur]); } } } void dfs(int cur, int p, int k) { for(int i=0; i<g[cur].size(); i++) { int viz=g[cur][i]; int ind=lista[cur][i]; if(viz==p||gin[viz]==0) continue; dfs(viz, cur, k^1); } if(!k) soma+=tenho[cur]; else soma-=tenho[cur]; } void solve(int cur, int p) { for(int i=0; i<g[cur].size(); i++) { int viz=g[cur][i]; int ind=lista[cur][i]; if(viz==p||gin[viz]==0) continue; if(cur==p) resp[ind]=soma; else resp[ind]=v[cur]-tenho[cur]; tenho[viz]+=soma; solve(viz, cur); } } int main() { scanf("%d %d", &n, &m); for(int i=1; i<=n; i++) scanf("%lld", &v[i]), v[i]*=2; for(int i=1; i<=m; i++) { int a, b; scanf("%d %d", &a, &b); g[a].push_back(b); g[b].push_back(a); gin[a]++; gin[b]++; lista[a].push_back(i); lista[b].push_back(i); } poda(); // for(int i=1; i<=n; i++) cout << tenho[i] << endl; if(m>n||(n-ncyc.size())%2==0) { printf("0\n"); return 0; } if(m==n-1&&tenho[ncyc.back()]!=v[ncyc.back()]) { printf("0\n"); return 0; } for(int i=1; i<=n; i++) { if(!gin[i]) continue; dfs(i, i, 0); solve(i, i); break; } for(int i=1; i<=m; i++) printf("%lld\n", resp[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5120 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 8 ms | 5092 KB | Output is correct |
4 | Correct | 126 ms | 15344 KB | Output is correct |
5 | Correct | 7 ms | 5120 KB | Output is correct |
6 | Correct | 8 ms | 5248 KB | Output is correct |
7 | Correct | 6 ms | 5120 KB | Output is correct |
8 | Correct | 6 ms | 5120 KB | Output is correct |
9 | Correct | 7 ms | 5120 KB | Output is correct |
10 | Correct | 7 ms | 5120 KB | Output is correct |
11 | Correct | 6 ms | 5120 KB | Output is correct |
12 | Correct | 6 ms | 5120 KB | Output is correct |
13 | Correct | 88 ms | 13296 KB | Output is correct |
14 | Correct | 137 ms | 14784 KB | Output is correct |
15 | Correct | 144 ms | 15356 KB | Output is correct |
16 | Correct | 118 ms | 13920 KB | Output is correct |
17 | Correct | 135 ms | 15472 KB | Output is correct |
18 | Correct | 136 ms | 15304 KB | Output is correct |
19 | Correct | 171 ms | 15092 KB | Output is correct |
20 | Correct | 6 ms | 5120 KB | Output is correct |
21 | Correct | 8 ms | 5120 KB | Output is correct |
22 | Correct | 151 ms | 15348 KB | Output is correct |
23 | Correct | 110 ms | 13268 KB | Output is correct |
24 | Correct | 147 ms | 15232 KB | Output is correct |
25 | Correct | 154 ms | 13808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 109 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Runtime error | 132 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
3 | Correct | 106 ms | 14276 KB | Output is correct |
4 | Correct | 126 ms | 14300 KB | Output is correct |
5 | Correct | 133 ms | 14680 KB | Output is correct |
6 | Runtime error | 467 ms | 43544 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
7 | Runtime error | 111 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
8 | Runtime error | 102 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
9 | Correct | 5 ms | 4992 KB | Output is correct |
10 | Correct | 5 ms | 4992 KB | Output is correct |
11 | Correct | 6 ms | 5120 KB | Output is correct |
12 | Correct | 6 ms | 4992 KB | Output is correct |
13 | Correct | 8 ms | 5120 KB | Output is correct |
14 | Runtime error | 110 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
15 | Runtime error | 121 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
16 | Runtime error | 123 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
17 | Correct | 8 ms | 5120 KB | Output is correct |
18 | Correct | 7 ms | 5120 KB | Output is correct |
19 | Correct | 7 ms | 5120 KB | Output is correct |
20 | Correct | 6 ms | 5120 KB | Output is correct |
21 | Correct | 8 ms | 5120 KB | Output is correct |
22 | Runtime error | 120 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
23 | Runtime error | 559 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
24 | Runtime error | 557 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
25 | Correct | 117 ms | 14164 KB | Output is correct |
26 | Correct | 115 ms | 14428 KB | Output is correct |
27 | Correct | 156 ms | 14072 KB | Output is correct |
28 | Correct | 145 ms | 14708 KB | Output is correct |
29 | Runtime error | 389 ms | 39568 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
30 | Runtime error | 578 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
31 | Runtime error | 582 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
32 | Runtime error | 480 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
33 | Correct | 132 ms | 14712 KB | Output is correct |
34 | Correct | 97 ms | 14320 KB | Output is correct |
35 | Correct | 115 ms | 14388 KB | Output is correct |
36 | Correct | 110 ms | 14716 KB | Output is correct |
37 | Runtime error | 469 ms | 43460 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
38 | Runtime error | 532 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
39 | Runtime error | 300 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
40 | Runtime error | 566 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
41 | Correct | 101 ms | 14200 KB | Output is correct |
42 | Correct | 104 ms | 14200 KB | Output is correct |
43 | Correct | 120 ms | 14016 KB | Output is correct |
44 | Correct | 136 ms | 14724 KB | Output is correct |
45 | Correct | 266 ms | 18552 KB | Output is correct |
46 | Runtime error | 490 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
47 | Runtime error | 581 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
48 | Runtime error | 563 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
49 | Correct | 145 ms | 14520 KB | Output is correct |
50 | Correct | 119 ms | 14540 KB | Output is correct |
51 | Correct | 150 ms | 14696 KB | Output is correct |
52 | Correct | 123 ms | 14200 KB | Output is correct |
53 | Correct | 430 ms | 18976 KB | Output is correct |
54 | Runtime error | 380 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |