#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 5e5+10;
int n, m, c[maxn], ans[maxn], gr[maxn];
vector<pair<int,int>> g[maxn], g1[maxn];
int beg;
vector<int> vrt;
void dfs(int u, int ant, int cnt) {
auto V = g1[u][0];
if(V.fr == ant) V = g1[u][1];
int v = V.fr;
int id = V.sc;
ans[id] = c[beg]*cnt;
if(v == beg) return;
dfs(v,u,cnt*-1);
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
for(int i = 1; i <= m; i++) {
int u,v; cin >> u >> v;
g[u].pb(mp(v,i));
g[v].pb(mp(u,i));
gr[u]++;
gr[v]++;
}
if(m > n) {
cout << 0 << endl;
return;
}
queue<int> q;
for(int i = 1; i <= n; i++) {
if(gr[i] == 1) q.push(i);
}
while(q.size()) {
int u = q.front(); q.pop();
gr[u] = -1;
for(auto V : g[u]) {
int v = V.fr;
int id = V.sc;
if(gr[v] == -1) continue;
ans[id] = 2*c[u];
c[v]-= c[u];
if(--gr[v] == 1) q.push(v);
}
}
if(m == n) {
for(int i = 1; i <= n; i++) {
if(gr[i] != -1) {
vrt.pb(i);
for(auto V : g[i]) {
if(gr[V.fr] != -1) {
g1[i].pb(V);
}
}
}
}
if(vrt.size()%2 == 1) {
for(auto x : vrt) {
if(c[x]) beg = x;
}
dfs(beg,-1,1);
}
else {
}
}
for(int i = 1; i <= m; i++) {
cout << ans[i] << endl;
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23744 KB |
Output is correct |
3 |
Correct |
13 ms |
23904 KB |
Output is correct |
4 |
Correct |
68 ms |
32672 KB |
Output is correct |
5 |
Correct |
12 ms |
23728 KB |
Output is correct |
6 |
Correct |
12 ms |
23832 KB |
Output is correct |
7 |
Correct |
12 ms |
23800 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23816 KB |
Output is correct |
10 |
Correct |
12 ms |
23876 KB |
Output is correct |
11 |
Correct |
12 ms |
23920 KB |
Output is correct |
12 |
Correct |
14 ms |
23908 KB |
Output is correct |
13 |
Correct |
63 ms |
30932 KB |
Output is correct |
14 |
Correct |
63 ms |
32140 KB |
Output is correct |
15 |
Correct |
67 ms |
32752 KB |
Output is correct |
16 |
Correct |
63 ms |
31344 KB |
Output is correct |
17 |
Correct |
74 ms |
32632 KB |
Output is correct |
18 |
Correct |
76 ms |
32748 KB |
Output is correct |
19 |
Correct |
79 ms |
32360 KB |
Output is correct |
20 |
Correct |
12 ms |
23796 KB |
Output is correct |
21 |
Correct |
13 ms |
23904 KB |
Output is correct |
22 |
Correct |
75 ms |
32716 KB |
Output is correct |
23 |
Correct |
62 ms |
30976 KB |
Output is correct |
24 |
Correct |
78 ms |
32724 KB |
Output is correct |
25 |
Correct |
59 ms |
31288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23724 KB |
Output isn't correct |
2 |
Incorrect |
13 ms |
23892 KB |
Output isn't correct |
3 |
Incorrect |
68 ms |
34444 KB |
Output isn't correct |
4 |
Correct |
62 ms |
31464 KB |
Output is correct |
5 |
Correct |
63 ms |
31204 KB |
Output is correct |
6 |
Correct |
197 ms |
52208 KB |
Output is correct |
7 |
Incorrect |
13 ms |
23764 KB |
Output isn't correct |
8 |
Incorrect |
14 ms |
23812 KB |
Output isn't correct |
9 |
Incorrect |
13 ms |
23808 KB |
Output isn't correct |
10 |
Correct |
15 ms |
23764 KB |
Output is correct |
11 |
Correct |
12 ms |
23764 KB |
Output is correct |
12 |
Correct |
16 ms |
23740 KB |
Output is correct |
13 |
Correct |
13 ms |
23764 KB |
Output is correct |
14 |
Incorrect |
14 ms |
23764 KB |
Output isn't correct |
15 |
Incorrect |
13 ms |
23948 KB |
Output isn't correct |
16 |
Incorrect |
12 ms |
23892 KB |
Output isn't correct |
17 |
Incorrect |
13 ms |
23892 KB |
Output isn't correct |
18 |
Correct |
12 ms |
23892 KB |
Output is correct |
19 |
Correct |
12 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23892 KB |
Output is correct |
21 |
Correct |
12 ms |
24084 KB |
Output is correct |
22 |
Incorrect |
12 ms |
23820 KB |
Output isn't correct |
23 |
Incorrect |
65 ms |
33744 KB |
Output isn't correct |
24 |
Incorrect |
85 ms |
35596 KB |
Output isn't correct |
25 |
Incorrect |
83 ms |
34352 KB |
Output isn't correct |
26 |
Correct |
56 ms |
31412 KB |
Output is correct |
27 |
Correct |
55 ms |
31368 KB |
Output is correct |
28 |
Correct |
54 ms |
31660 KB |
Output is correct |
29 |
Correct |
160 ms |
46936 KB |
Output is correct |
30 |
Incorrect |
87 ms |
34872 KB |
Output isn't correct |
31 |
Incorrect |
89 ms |
37312 KB |
Output isn't correct |
32 |
Incorrect |
71 ms |
33480 KB |
Output isn't correct |
33 |
Incorrect |
70 ms |
35520 KB |
Output isn't correct |
34 |
Correct |
64 ms |
31384 KB |
Output is correct |
35 |
Correct |
58 ms |
31484 KB |
Output is correct |
36 |
Correct |
55 ms |
31396 KB |
Output is correct |
37 |
Correct |
181 ms |
52212 KB |
Output is correct |
38 |
Incorrect |
87 ms |
35176 KB |
Output isn't correct |
39 |
Incorrect |
82 ms |
33100 KB |
Output isn't correct |
40 |
Incorrect |
97 ms |
35252 KB |
Output isn't correct |
41 |
Incorrect |
74 ms |
37108 KB |
Output isn't correct |
42 |
Correct |
63 ms |
31340 KB |
Output is correct |
43 |
Correct |
65 ms |
31364 KB |
Output is correct |
44 |
Correct |
57 ms |
31120 KB |
Output is correct |
45 |
Correct |
149 ms |
49160 KB |
Output is correct |
46 |
Incorrect |
86 ms |
34692 KB |
Output isn't correct |
47 |
Incorrect |
78 ms |
35416 KB |
Output isn't correct |
48 |
Incorrect |
88 ms |
37184 KB |
Output isn't correct |
49 |
Incorrect |
65 ms |
32848 KB |
Output isn't correct |
50 |
Correct |
52 ms |
31368 KB |
Output is correct |
51 |
Correct |
53 ms |
31436 KB |
Output is correct |
52 |
Correct |
52 ms |
31264 KB |
Output is correct |
53 |
Correct |
165 ms |
48724 KB |
Output is correct |
54 |
Incorrect |
90 ms |
34488 KB |
Output isn't correct |