#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];
void solve() {
cin >> n >> m;
if(m != n-1) {
assert(m > n-1);
cout << 0 << endl;
return;
}
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
if(n == 2) {
cout << 2*c[1] << endl;
return;
}
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]++;
}
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);
}
}
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 |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
12116 KB |
Output is correct |
4 |
Correct |
63 ms |
20356 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
12116 KB |
Output is correct |
10 |
Correct |
6 ms |
12116 KB |
Output is correct |
11 |
Correct |
6 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12176 KB |
Output is correct |
13 |
Correct |
45 ms |
18676 KB |
Output is correct |
14 |
Correct |
56 ms |
19848 KB |
Output is correct |
15 |
Correct |
58 ms |
20444 KB |
Output is correct |
16 |
Correct |
51 ms |
19024 KB |
Output is correct |
17 |
Correct |
59 ms |
20332 KB |
Output is correct |
18 |
Correct |
58 ms |
20392 KB |
Output is correct |
19 |
Correct |
61 ms |
20044 KB |
Output is correct |
20 |
Correct |
6 ms |
12088 KB |
Output is correct |
21 |
Correct |
6 ms |
12116 KB |
Output is correct |
22 |
Correct |
58 ms |
20360 KB |
Output is correct |
23 |
Correct |
49 ms |
18608 KB |
Output is correct |
24 |
Correct |
66 ms |
20428 KB |
Output is correct |
25 |
Correct |
48 ms |
18932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
12072 KB |
Output isn't correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Incorrect |
7 ms |
11988 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
11988 KB |
Output isn't correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
7 ms |
12052 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11992 KB |
Output is correct |
13 |
Correct |
6 ms |
12068 KB |
Output is correct |
14 |
Incorrect |
7 ms |
12040 KB |
Output isn't correct |
15 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
16 |
Incorrect |
6 ms |
12048 KB |
Output isn't correct |
17 |
Correct |
6 ms |
11988 KB |
Output is correct |
18 |
Correct |
6 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
11956 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
23 |
Incorrect |
6 ms |
12064 KB |
Output isn't correct |
24 |
Incorrect |
7 ms |
11988 KB |
Output isn't correct |
25 |
Correct |
7 ms |
11988 KB |
Output is correct |
26 |
Correct |
6 ms |
11988 KB |
Output is correct |
27 |
Correct |
6 ms |
11988 KB |
Output is correct |
28 |
Correct |
7 ms |
11988 KB |
Output is correct |
29 |
Correct |
6 ms |
11988 KB |
Output is correct |
30 |
Incorrect |
7 ms |
12060 KB |
Output isn't correct |
31 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
32 |
Incorrect |
7 ms |
11980 KB |
Output isn't correct |
33 |
Correct |
7 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
11988 KB |
Output is correct |
36 |
Correct |
6 ms |
12004 KB |
Output is correct |
37 |
Correct |
6 ms |
12076 KB |
Output is correct |
38 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
39 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
40 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
41 |
Correct |
7 ms |
11988 KB |
Output is correct |
42 |
Correct |
6 ms |
11988 KB |
Output is correct |
43 |
Correct |
6 ms |
12076 KB |
Output is correct |
44 |
Correct |
6 ms |
11988 KB |
Output is correct |
45 |
Correct |
6 ms |
12020 KB |
Output is correct |
46 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
47 |
Incorrect |
6 ms |
12052 KB |
Output isn't correct |
48 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
49 |
Correct |
6 ms |
11988 KB |
Output is correct |
50 |
Correct |
6 ms |
11988 KB |
Output is correct |
51 |
Correct |
7 ms |
11988 KB |
Output is correct |
52 |
Correct |
6 ms |
11988 KB |
Output is correct |
53 |
Correct |
6 ms |
12000 KB |
Output is correct |
54 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |