#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);
cout << 0 << "\n";
return 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) {
cout << "0\n";
return 0;
}
dfs(1);
int lca = 0;
if (bEdge != -1) {
auto u = edges[bEdge];
int a = u.fr, b = u.se;
if (h[a] > h[b]) swap(a, b);
// a is higher than b
int oa = a, ob = b;
while (h[b] > h[a]) {
b = dad[b];
}
while (a != b) {
a = dad[a];
b = dad[b];
}
lca = a;
a = oa;
b = ob;
int tam = h[a] + h[b] - 2*h[lca] + 1;
if ((tam % 2LL) == 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;
}
// first case is for tree
// second case is if you can't add 2x to it
if ((bEdge == -1) || ((change[1] - dp[1]) % 2LL)) {
cout << "0\n";
return 0;
}
//cout << "0\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
3616 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
3416 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
3416 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
3672 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
3416 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
9 |
Correct |
1 ms |
3416 KB |
Output is correct |
10 |
Correct |
1 ms |
3416 KB |
Output is correct |
11 |
Correct |
1 ms |
3564 KB |
Output is correct |
12 |
Correct |
1 ms |
3420 KB |
Output is correct |
13 |
Correct |
1 ms |
3420 KB |
Output is correct |
14 |
Incorrect |
1 ms |
3416 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
17 |
Correct |
1 ms |
3412 KB |
Output is correct |
18 |
Correct |
1 ms |
3416 KB |
Output is correct |
19 |
Correct |
1 ms |
3416 KB |
Output is correct |
20 |
Correct |
1 ms |
3420 KB |
Output is correct |
21 |
Correct |
1 ms |
3420 KB |
Output is correct |
22 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
25 |
Correct |
1 ms |
3420 KB |
Output is correct |
26 |
Correct |
1 ms |
3420 KB |
Output is correct |
27 |
Correct |
1 ms |
3416 KB |
Output is correct |
28 |
Correct |
1 ms |
3420 KB |
Output is correct |
29 |
Correct |
1 ms |
3420 KB |
Output is correct |
30 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
33 |
Correct |
1 ms |
3672 KB |
Output is correct |
34 |
Correct |
1 ms |
3420 KB |
Output is correct |
35 |
Correct |
1 ms |
3420 KB |
Output is correct |
36 |
Correct |
1 ms |
3420 KB |
Output is correct |
37 |
Correct |
1 ms |
3420 KB |
Output is correct |
38 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
40 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
41 |
Correct |
1 ms |
3420 KB |
Output is correct |
42 |
Correct |
1 ms |
3416 KB |
Output is correct |
43 |
Correct |
1 ms |
3420 KB |
Output is correct |
44 |
Correct |
1 ms |
3420 KB |
Output is correct |
45 |
Correct |
1 ms |
3420 KB |
Output is correct |
46 |
Incorrect |
1 ms |
3372 KB |
Output isn't correct |
47 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
48 |
Incorrect |
1 ms |
3420 KB |
Output isn't correct |
49 |
Correct |
1 ms |
3420 KB |
Output is correct |
50 |
Correct |
2 ms |
3420 KB |
Output is correct |
51 |
Correct |
1 ms |
3420 KB |
Output is correct |
52 |
Correct |
1 ms |
3416 KB |
Output is correct |
53 |
Correct |
1 ms |
3432 KB |
Output is correct |
54 |
Incorrect |
1 ms |
3416 KB |
Output isn't correct |