# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26447 | 2017-06-30T19:12:43 Z | samir_droubi | Pipes (BOI13_pipes) | C++14 | 646 ms | 56308 KB |
#include <bits/stdc++.h> using namespace std; int n,m; const int mxn=(1e5)+5; set<pair<int,int> >gr[mxn]; queue<int>q; long long c[mxn]; int ans[mxn*5]; void run() { while(!q.empty()) { int v=q.front(); q.pop(); if(gr[v].empty())continue; int u=gr[v].begin()->first; int in=gr[v].begin()->second; gr[v].clear(); gr[u].erase({v,in}); if(gr[u].size()==1)q.push(u); ans[in]=2*c[v]; c[u]-=c[v]; } } long long sm; int num; int cnt; void dfs(int v,int pa) { ++num; if(num%2)sm+=c[v]; else sm-=c[v]; set<pair<int,int > >::iterator it=gr[v].begin(); for(it;it!=gr[v].end();++it) { int u=it->first; int in=it->second; if(u==pa)continue; if(cnt==num) { ans[in]=sm; c[u]-=(sm/2); c[v]-=(sm/2); gr[u].erase({v,in}); gr[v].erase(it); q.push(v); return; } dfs(u,v); } } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i)scanf("%d",&c[i]); for(int i=1;i<=m;++i) { int x,y; scanf("%d%d",&x,&y); gr[x].insert({y,i}); gr[y].insert({x,i}); } if(m>n) { puts("0"); return 0; } for(int i=1;i<=n;++i) { if(gr[i].size()==1) q.push(i); } run(); if(n==m) { for(int i=1;i<=n;++i) { if(gr[i].empty())continue; ++cnt; } if(cnt%2==0) { puts("0"); return 0; } for(int i=1;i<=n;++i) { if(gr[i].empty())continue; dfs(i,i); break; } run(); } for(int i=1;i<=m;++i) printf("%d\n",ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 9448 KB | Output is correct |
2 | Correct | 0 ms | 9448 KB | Output is correct |
3 | Correct | 0 ms | 9580 KB | Output is correct |
4 | Correct | 139 ms | 18952 KB | Output is correct |
5 | Correct | 0 ms | 9448 KB | Output is correct |
6 | Correct | 0 ms | 9448 KB | Output is correct |
7 | Correct | 3 ms | 9448 KB | Output is correct |
8 | Correct | 0 ms | 9448 KB | Output is correct |
9 | Correct | 3 ms | 9580 KB | Output is correct |
10 | Correct | 0 ms | 9580 KB | Output is correct |
11 | Correct | 0 ms | 9580 KB | Output is correct |
12 | Correct | 0 ms | 9580 KB | Output is correct |
13 | Correct | 109 ms | 17104 KB | Output is correct |
14 | Correct | 129 ms | 18424 KB | Output is correct |
15 | Correct | 166 ms | 19084 KB | Output is correct |
16 | Correct | 126 ms | 17632 KB | Output is correct |
17 | Correct | 149 ms | 18952 KB | Output is correct |
18 | Correct | 163 ms | 19084 KB | Output is correct |
19 | Correct | 126 ms | 18820 KB | Output is correct |
20 | Correct | 0 ms | 9448 KB | Output is correct |
21 | Correct | 0 ms | 9580 KB | Output is correct |
22 | Correct | 163 ms | 19084 KB | Output is correct |
23 | Correct | 123 ms | 17104 KB | Output is correct |
24 | Correct | 176 ms | 19084 KB | Output is correct |
25 | Correct | 126 ms | 17368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 9448 KB | Output is correct |
2 | Correct | 3 ms | 9580 KB | Output is correct |
3 | Correct | 129 ms | 18424 KB | Output is correct |
4 | Correct | 96 ms | 18820 KB | Output is correct |
5 | Correct | 113 ms | 18556 KB | Output is correct |
6 | Correct | 626 ms | 56308 KB | Output is correct |
7 | Correct | 0 ms | 9448 KB | Output is correct |
8 | Correct | 0 ms | 9448 KB | Output is correct |
9 | Correct | 0 ms | 9448 KB | Output is correct |
10 | Correct | 0 ms | 9448 KB | Output is correct |
11 | Correct | 3 ms | 9448 KB | Output is correct |
12 | Correct | 3 ms | 9448 KB | Output is correct |
13 | Correct | 0 ms | 9448 KB | Output is correct |
14 | Correct | 0 ms | 9448 KB | Output is correct |
15 | Correct | 0 ms | 9580 KB | Output is correct |
16 | Correct | 3 ms | 9580 KB | Output is correct |
17 | Correct | 0 ms | 9580 KB | Output is correct |
18 | Correct | 3 ms | 9580 KB | Output is correct |
19 | Correct | 0 ms | 9580 KB | Output is correct |
20 | Correct | 0 ms | 9580 KB | Output is correct |
21 | Correct | 6 ms | 9712 KB | Output is correct |
22 | Correct | 0 ms | 9580 KB | Output is correct |
23 | Correct | 126 ms | 20228 KB | Output is correct |
24 | Correct | 179 ms | 22116 KB | Output is correct |
25 | Correct | 113 ms | 18424 KB | Output is correct |
26 | Correct | 89 ms | 18820 KB | Output is correct |
27 | Correct | 109 ms | 18820 KB | Output is correct |
28 | Correct | 123 ms | 19348 KB | Output is correct |
29 | Correct | 469 ms | 47068 KB | Output is correct |
30 | Correct | 156 ms | 21372 KB | Output is correct |
31 | Correct | 166 ms | 24144 KB | Output is correct |
32 | Correct | 143 ms | 19880 KB | Output is correct |
33 | Correct | 143 ms | 18952 KB | Output is correct |
34 | Correct | 109 ms | 18820 KB | Output is correct |
35 | Correct | 139 ms | 18820 KB | Output is correct |
36 | Correct | 89 ms | 18952 KB | Output is correct |
37 | Correct | 646 ms | 56308 KB | Output is correct |
38 | Correct | 149 ms | 21584 KB | Output is correct |
39 | Correct | 169 ms | 19476 KB | Output is correct |
40 | Correct | 186 ms | 21796 KB | Output is correct |
41 | Correct | 99 ms | 18820 KB | Output is correct |
42 | Correct | 96 ms | 18820 KB | Output is correct |
43 | Correct | 129 ms | 18820 KB | Output is correct |
44 | Correct | 89 ms | 18556 KB | Output is correct |
45 | Correct | 583 ms | 51028 KB | Output is correct |
46 | Correct | 149 ms | 21240 KB | Output is correct |
47 | Correct | 159 ms | 21900 KB | Output is correct |
48 | Correct | 183 ms | 23940 KB | Output is correct |
49 | Correct | 133 ms | 18424 KB | Output is correct |
50 | Correct | 96 ms | 18820 KB | Output is correct |
51 | Correct | 99 ms | 18820 KB | Output is correct |
52 | Correct | 89 ms | 18688 KB | Output is correct |
53 | Correct | 543 ms | 51820 KB | Output is correct |
54 | Correct | 173 ms | 20992 KB | Output is correct |