#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
const int MAXN = 1e5 + 10;
const int MAXM = 5e5 + 10;
vector<pii> adj[MAXN];
int bEdge = -1;
vector<pii> edges;
int h[MAXN];
int change[MAXN];
bool vis[MAXN];
int dad[MAXN];
int dp[MAXN];
int peso[MAXM];
void dfs(int node) {
vis[node] = 1;
for (auto [u, z] : adj[node]) {
if (u == dad[node]) continue;
if (vis[u]) bEdge = z;
else {
dad[u] = node;
h[u] = h[node] + 1;
dfs(u);
}
}
}
void calc(int node) {
vis[node] = 1;
for (auto [u, z] : adj[node]) {
if (vis[u]) continue;
calc(u);
dp[node] += (change[u] - dp[u]);
peso[z] += (change[u] - dp[u]);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> change[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
edges.push_back({a, b});
adj[a].push_back({b, i});
adj[b].push_back({a, i});
}
if (m > (n + 1)) {
cout << "0\n";
return 0;
}
dfs(1);
if (bEdge != -1) {
auto u = edges[bEdge];
if (((h[u.fr] + h[u.se] + 1) % 2) == 0) {
cout << "0\n";
return 0;
}
}
memset(vis, 0, sizeof vis);
calc(1);
if (dp[1] == change[1]) {
for (int i = 0; i < m; i++) cout << 2*peso[i] << "\n";
return 0;
}
if (bEdge == -1) {
cout << "0\n";
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5464 KB |
Output is correct |
2 |
Correct |
1 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5720 KB |
Output is correct |
4 |
Correct |
37 ms |
18416 KB |
Output is correct |
5 |
Correct |
1 ms |
5468 KB |
Output is correct |
6 |
Correct |
1 ms |
5468 KB |
Output is correct |
7 |
Correct |
1 ms |
5464 KB |
Output is correct |
8 |
Correct |
1 ms |
5468 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5720 KB |
Output is correct |
11 |
Correct |
1 ms |
5636 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
25 ms |
15052 KB |
Output is correct |
14 |
Correct |
31 ms |
16392 KB |
Output is correct |
15 |
Correct |
34 ms |
16844 KB |
Output is correct |
16 |
Correct |
27 ms |
15504 KB |
Output is correct |
17 |
Correct |
31 ms |
18548 KB |
Output is correct |
18 |
Correct |
41 ms |
18592 KB |
Output is correct |
19 |
Correct |
38 ms |
22464 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
32 ms |
18496 KB |
Output is correct |
23 |
Correct |
25 ms |
15044 KB |
Output is correct |
24 |
Correct |
31 ms |
16836 KB |
Output is correct |
25 |
Correct |
26 ms |
17092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
3 |
Correct |
27 ms |
16572 KB |
Output is correct |
4 |
Incorrect |
40 ms |
24004 KB |
Output isn't correct |
5 |
Correct |
29 ms |
13508 KB |
Output is correct |
6 |
Correct |
100 ms |
45484 KB |
Output is correct |
7 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
9 |
Correct |
1 ms |
5468 KB |
Output is correct |
10 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
12 |
Correct |
1 ms |
5468 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Incorrect |
1 ms |
5468 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Incorrect |
1 ms |
5720 KB |
Output isn't correct |
23 |
Incorrect |
31 ms |
18932 KB |
Output isn't correct |
24 |
Incorrect |
35 ms |
20468 KB |
Output isn't correct |
25 |
Correct |
26 ms |
16076 KB |
Output is correct |
26 |
Incorrect |
34 ms |
21524 KB |
Output isn't correct |
27 |
Incorrect |
33 ms |
22220 KB |
Output isn't correct |
28 |
Correct |
23 ms |
14348 KB |
Output is correct |
29 |
Correct |
76 ms |
38320 KB |
Output is correct |
30 |
Incorrect |
38 ms |
24712 KB |
Output isn't correct |
31 |
Incorrect |
34 ms |
24872 KB |
Output isn't correct |
32 |
Incorrect |
29 ms |
17660 KB |
Output isn't correct |
33 |
Correct |
28 ms |
17356 KB |
Output is correct |
34 |
Incorrect |
34 ms |
20928 KB |
Output isn't correct |
35 |
Incorrect |
35 ms |
24000 KB |
Output isn't correct |
36 |
Correct |
22 ms |
14016 KB |
Output is correct |
37 |
Correct |
94 ms |
45396 KB |
Output is correct |
38 |
Incorrect |
34 ms |
22212 KB |
Output isn't correct |
39 |
Incorrect |
28 ms |
17096 KB |
Output isn't correct |
40 |
Incorrect |
30 ms |
21804 KB |
Output isn't correct |
41 |
Correct |
29 ms |
19396 KB |
Output is correct |
42 |
Incorrect |
33 ms |
22976 KB |
Output isn't correct |
43 |
Incorrect |
35 ms |
24444 KB |
Output isn't correct |
44 |
Correct |
23 ms |
13504 KB |
Output is correct |
45 |
Correct |
71 ms |
42444 KB |
Output is correct |
46 |
Incorrect |
41 ms |
23904 KB |
Output isn't correct |
47 |
Incorrect |
32 ms |
20476 KB |
Output isn't correct |
48 |
Incorrect |
39 ms |
22976 KB |
Output isn't correct |
49 |
Correct |
28 ms |
14272 KB |
Output is correct |
50 |
Incorrect |
34 ms |
20932 KB |
Output isn't correct |
51 |
Incorrect |
30 ms |
19080 KB |
Output isn't correct |
52 |
Correct |
24 ms |
13772 KB |
Output is correct |
53 |
Correct |
85 ms |
40988 KB |
Output is correct |
54 |
Incorrect |
33 ms |
21700 KB |
Output isn't correct |