#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i <y;i++)
using namespace std;const int N=6e5;int n,m;set<pair<int,int>>g[N];int c[N],A[N],V[N],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
28536 KB |
Output is correct |
2 |
Correct |
22 ms |
28536 KB |
Output is correct |
3 |
Correct |
25 ms |
28664 KB |
Output is correct |
4 |
Correct |
233 ms |
38776 KB |
Output is correct |
5 |
Correct |
22 ms |
28536 KB |
Output is correct |
6 |
Correct |
22 ms |
28536 KB |
Output is correct |
7 |
Correct |
24 ms |
28536 KB |
Output is correct |
8 |
Correct |
22 ms |
28536 KB |
Output is correct |
9 |
Correct |
24 ms |
28664 KB |
Output is correct |
10 |
Correct |
23 ms |
28664 KB |
Output is correct |
11 |
Correct |
24 ms |
28664 KB |
Output is correct |
12 |
Correct |
23 ms |
28664 KB |
Output is correct |
13 |
Correct |
189 ms |
36728 KB |
Output is correct |
14 |
Correct |
225 ms |
38264 KB |
Output is correct |
15 |
Correct |
233 ms |
38904 KB |
Output is correct |
16 |
Correct |
198 ms |
37368 KB |
Output is correct |
17 |
Correct |
229 ms |
38888 KB |
Output is correct |
18 |
Correct |
229 ms |
38904 KB |
Output is correct |
19 |
Correct |
206 ms |
39160 KB |
Output is correct |
20 |
Correct |
22 ms |
28536 KB |
Output is correct |
21 |
Correct |
23 ms |
28664 KB |
Output is correct |
22 |
Correct |
234 ms |
38908 KB |
Output is correct |
23 |
Correct |
185 ms |
36728 KB |
Output is correct |
24 |
Correct |
228 ms |
39032 KB |
Output is correct |
25 |
Correct |
188 ms |
37104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
28536 KB |
Output is correct |
2 |
Correct |
25 ms |
28664 KB |
Output is correct |
3 |
Correct |
196 ms |
38268 KB |
Output is correct |
4 |
Correct |
189 ms |
38776 KB |
Output is correct |
5 |
Correct |
206 ms |
38648 KB |
Output is correct |
6 |
Correct |
859 ms |
75896 KB |
Output is correct |
7 |
Correct |
22 ms |
28536 KB |
Output is correct |
8 |
Correct |
22 ms |
28540 KB |
Output is correct |
9 |
Correct |
22 ms |
28536 KB |
Output is correct |
10 |
Correct |
22 ms |
28540 KB |
Output is correct |
11 |
Correct |
22 ms |
28536 KB |
Output is correct |
12 |
Correct |
22 ms |
28536 KB |
Output is correct |
13 |
Correct |
22 ms |
28536 KB |
Output is correct |
14 |
Correct |
22 ms |
28536 KB |
Output is correct |
15 |
Correct |
23 ms |
28664 KB |
Output is correct |
16 |
Correct |
24 ms |
28664 KB |
Output is correct |
17 |
Correct |
23 ms |
28664 KB |
Output is correct |
18 |
Correct |
24 ms |
28664 KB |
Output is correct |
19 |
Correct |
23 ms |
28664 KB |
Output is correct |
20 |
Correct |
24 ms |
28664 KB |
Output is correct |
21 |
Correct |
26 ms |
28792 KB |
Output is correct |
22 |
Correct |
24 ms |
28664 KB |
Output is correct |
23 |
Correct |
200 ms |
40836 KB |
Output is correct |
24 |
Correct |
243 ms |
42872 KB |
Output is correct |
25 |
Correct |
198 ms |
38264 KB |
Output is correct |
26 |
Correct |
196 ms |
38936 KB |
Output is correct |
27 |
Correct |
185 ms |
38648 KB |
Output is correct |
28 |
Correct |
215 ms |
39288 KB |
Output is correct |
29 |
Correct |
692 ms |
67192 KB |
Output is correct |
30 |
Correct |
225 ms |
42140 KB |
Output is correct |
31 |
Correct |
235 ms |
45048 KB |
Output is correct |
32 |
Correct |
235 ms |
40648 KB |
Output is correct |
33 |
Correct |
222 ms |
38972 KB |
Output is correct |
34 |
Correct |
184 ms |
38776 KB |
Output is correct |
35 |
Correct |
187 ms |
38776 KB |
Output is correct |
36 |
Correct |
211 ms |
39032 KB |
Output is correct |
37 |
Correct |
871 ms |
75896 KB |
Output is correct |
38 |
Correct |
230 ms |
42488 KB |
Output is correct |
39 |
Correct |
255 ms |
40252 KB |
Output is correct |
40 |
Correct |
243 ms |
42788 KB |
Output is correct |
41 |
Correct |
185 ms |
38644 KB |
Output is correct |
42 |
Correct |
183 ms |
38776 KB |
Output is correct |
43 |
Correct |
191 ms |
38772 KB |
Output is correct |
44 |
Correct |
210 ms |
38524 KB |
Output is correct |
45 |
Correct |
805 ms |
70520 KB |
Output is correct |
46 |
Correct |
222 ms |
42104 KB |
Output is correct |
47 |
Correct |
252 ms |
42872 KB |
Output is correct |
48 |
Correct |
252 ms |
44920 KB |
Output is correct |
49 |
Correct |
209 ms |
38136 KB |
Output is correct |
50 |
Correct |
197 ms |
38760 KB |
Output is correct |
51 |
Correct |
204 ms |
38776 KB |
Output is correct |
52 |
Correct |
184 ms |
38520 KB |
Output is correct |
53 |
Correct |
817 ms |
71276 KB |
Output is correct |
54 |
Correct |
237 ms |
41860 KB |
Output is correct |