#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using ll = long long;
using namespace std;
const int maxn = 1<<19;
int n, m;
vector<array<ll, 2>> g[maxn];
ll val[maxn];
ll vis[maxn], C[maxn], h[maxn], back = -1, bb;
ll s = 0;
ll dfs(int v, int p) {
ll cur = C[v];
vis[v] = 1;
if(h[v]&1) s -= C[v];
else s += C[v];
for(auto &[i, id] : g[v]) if(i != p) {
if(!vis[i]) {
h[i] = h[v]+1;
ll t = dfs(i, v);
cur += t;
val[id] = t;
} else if(h[i] < h[v]) {
if(back != -1 || (h[i]&1) != (h[v]&1)) {cout << "0\n", exit(0);}
back = id, bb = h[v]&1;
}
}
return -cur;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> C[i];
for(int f, t, i = 0; i < m; i++) {
cin >> f >> t;
g[f].push_back({t, i});
g[t].push_back({f, i});
}
dfs(1, 1);
if(back != -1) val[back] = bb?s:-s;
for(int i = 0; i < m; i++) cout << -2ll*val[i] << "\n"; cout << endl;
}
//?VK
//??V
//K?
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
41 | for(int i = 0; i < m; i++) cout << -2ll*val[i] << "\n"; cout << endl;
| ^~~
pipes.cpp:41:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
41 | for(int i = 0; i < m; i++) cout << -2ll*val[i] << "\n"; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12672 KB |
Output is correct |
2 |
Correct |
9 ms |
12672 KB |
Output is correct |
3 |
Correct |
10 ms |
12928 KB |
Output is correct |
4 |
Correct |
84 ms |
21372 KB |
Output is correct |
5 |
Correct |
9 ms |
12672 KB |
Output is correct |
6 |
Correct |
9 ms |
12672 KB |
Output is correct |
7 |
Correct |
9 ms |
12672 KB |
Output is correct |
8 |
Correct |
9 ms |
12672 KB |
Output is correct |
9 |
Correct |
10 ms |
12800 KB |
Output is correct |
10 |
Correct |
10 ms |
12800 KB |
Output is correct |
11 |
Correct |
10 ms |
12800 KB |
Output is correct |
12 |
Correct |
10 ms |
12800 KB |
Output is correct |
13 |
Correct |
65 ms |
19576 KB |
Output is correct |
14 |
Correct |
77 ms |
20856 KB |
Output is correct |
15 |
Correct |
85 ms |
21496 KB |
Output is correct |
16 |
Correct |
72 ms |
20088 KB |
Output is correct |
17 |
Correct |
88 ms |
21500 KB |
Output is correct |
18 |
Correct |
83 ms |
21368 KB |
Output is correct |
19 |
Correct |
94 ms |
24440 KB |
Output is correct |
20 |
Correct |
10 ms |
12672 KB |
Output is correct |
21 |
Correct |
11 ms |
12800 KB |
Output is correct |
22 |
Correct |
90 ms |
21368 KB |
Output is correct |
23 |
Correct |
68 ms |
19576 KB |
Output is correct |
24 |
Correct |
93 ms |
21368 KB |
Output is correct |
25 |
Correct |
80 ms |
19960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
12800 KB |
Output isn't correct |
3 |
Correct |
84 ms |
23416 KB |
Output is correct |
4 |
Correct |
94 ms |
25704 KB |
Output is correct |
5 |
Correct |
65 ms |
20728 KB |
Output is correct |
6 |
Correct |
270 ms |
39636 KB |
Output is correct |
7 |
Incorrect |
10 ms |
12672 KB |
Output isn't correct |
8 |
Incorrect |
10 ms |
12672 KB |
Output isn't correct |
9 |
Correct |
9 ms |
12672 KB |
Output is correct |
10 |
Correct |
9 ms |
12672 KB |
Output is correct |
11 |
Correct |
9 ms |
12672 KB |
Output is correct |
12 |
Correct |
9 ms |
12672 KB |
Output is correct |
13 |
Correct |
9 ms |
12672 KB |
Output is correct |
14 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
15 |
Incorrect |
10 ms |
12800 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
12800 KB |
Output isn't correct |
17 |
Correct |
10 ms |
12928 KB |
Output is correct |
18 |
Correct |
10 ms |
12800 KB |
Output is correct |
19 |
Correct |
10 ms |
12800 KB |
Output is correct |
20 |
Correct |
11 ms |
12800 KB |
Output is correct |
21 |
Correct |
10 ms |
12900 KB |
Output is correct |
22 |
Incorrect |
13 ms |
12800 KB |
Output isn't correct |
23 |
Incorrect |
74 ms |
23144 KB |
Output isn't correct |
24 |
Incorrect |
97 ms |
24824 KB |
Output isn't correct |
25 |
Correct |
75 ms |
23288 KB |
Output is correct |
26 |
Correct |
88 ms |
25208 KB |
Output is correct |
27 |
Correct |
85 ms |
25464 KB |
Output is correct |
28 |
Correct |
65 ms |
19448 KB |
Output is correct |
29 |
Correct |
204 ms |
34416 KB |
Output is correct |
30 |
Incorrect |
95 ms |
26616 KB |
Output isn't correct |
31 |
Incorrect |
105 ms |
26892 KB |
Output isn't correct |
32 |
Incorrect |
98 ms |
22392 KB |
Output isn't correct |
33 |
Correct |
78 ms |
24440 KB |
Output is correct |
34 |
Correct |
89 ms |
24568 KB |
Output is correct |
35 |
Correct |
84 ms |
25720 KB |
Output is correct |
36 |
Correct |
63 ms |
21112 KB |
Output is correct |
37 |
Correct |
255 ms |
39672 KB |
Output is correct |
38 |
Incorrect |
97 ms |
26104 KB |
Output isn't correct |
39 |
Incorrect |
87 ms |
21980 KB |
Output isn't correct |
40 |
Incorrect |
92 ms |
24568 KB |
Output isn't correct |
41 |
Correct |
86 ms |
26488 KB |
Output is correct |
42 |
Correct |
92 ms |
24952 KB |
Output is correct |
43 |
Correct |
91 ms |
26104 KB |
Output is correct |
44 |
Correct |
62 ms |
20984 KB |
Output is correct |
45 |
Correct |
209 ms |
36600 KB |
Output is correct |
46 |
Incorrect |
101 ms |
27384 KB |
Output isn't correct |
47 |
Incorrect |
92 ms |
24568 KB |
Output isn't correct |
48 |
Incorrect |
97 ms |
26744 KB |
Output isn't correct |
49 |
Correct |
66 ms |
21368 KB |
Output is correct |
50 |
Correct |
83 ms |
24688 KB |
Output is correct |
51 |
Correct |
78 ms |
23032 KB |
Output is correct |
52 |
Correct |
65 ms |
21784 KB |
Output is correct |
53 |
Correct |
214 ms |
35960 KB |
Output is correct |
54 |
Incorrect |
104 ms |
25592 KB |
Output isn't correct |