#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;
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;
}
if(n == 2) {
cout << 2*c[1] << 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);
}
}
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 |
7 ms |
12104 KB |
Output is correct |
4 |
Correct |
59 ms |
20328 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
12116 KB |
Output is correct |
10 |
Correct |
7 ms |
12116 KB |
Output is correct |
11 |
Correct |
6 ms |
12180 KB |
Output is correct |
12 |
Correct |
6 ms |
12116 KB |
Output is correct |
13 |
Correct |
54 ms |
18648 KB |
Output is correct |
14 |
Correct |
56 ms |
19832 KB |
Output is correct |
15 |
Correct |
65 ms |
20372 KB |
Output is correct |
16 |
Correct |
50 ms |
19060 KB |
Output is correct |
17 |
Correct |
61 ms |
20284 KB |
Output is correct |
18 |
Correct |
61 ms |
20340 KB |
Output is correct |
19 |
Correct |
64 ms |
20056 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
7 ms |
12116 KB |
Output is correct |
22 |
Correct |
59 ms |
20384 KB |
Output is correct |
23 |
Correct |
48 ms |
18636 KB |
Output is correct |
24 |
Correct |
67 ms |
20512 KB |
Output is correct |
25 |
Correct |
51 ms |
18996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Incorrect |
58 ms |
20392 KB |
Output isn't correct |
4 |
Correct |
49 ms |
19504 KB |
Output is correct |
5 |
Correct |
44 ms |
19236 KB |
Output is correct |
6 |
Correct |
181 ms |
40232 KB |
Output is correct |
7 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
9 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
15 |
Incorrect |
7 ms |
12136 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
12076 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
12148 KB |
Output isn't correct |
18 |
Correct |
7 ms |
12116 KB |
Output is correct |
19 |
Correct |
7 ms |
12148 KB |
Output is correct |
20 |
Correct |
6 ms |
12116 KB |
Output is correct |
21 |
Correct |
7 ms |
12244 KB |
Output is correct |
22 |
Incorrect |
7 ms |
12116 KB |
Output isn't correct |
23 |
Incorrect |
49 ms |
19256 KB |
Output isn't correct |
24 |
Incorrect |
57 ms |
20792 KB |
Output isn't correct |
25 |
Incorrect |
53 ms |
20372 KB |
Output isn't correct |
26 |
Correct |
45 ms |
19532 KB |
Output is correct |
27 |
Correct |
50 ms |
19456 KB |
Output is correct |
28 |
Correct |
50 ms |
19720 KB |
Output is correct |
29 |
Correct |
145 ms |
34892 KB |
Output is correct |
30 |
Incorrect |
60 ms |
20368 KB |
Output isn't correct |
31 |
Incorrect |
53 ms |
20572 KB |
Output isn't correct |
32 |
Incorrect |
59 ms |
20992 KB |
Output isn't correct |
33 |
Incorrect |
61 ms |
20812 KB |
Output isn't correct |
34 |
Correct |
54 ms |
19504 KB |
Output is correct |
35 |
Correct |
45 ms |
19516 KB |
Output is correct |
36 |
Correct |
48 ms |
19496 KB |
Output is correct |
37 |
Correct |
175 ms |
40188 KB |
Output is correct |
38 |
Incorrect |
60 ms |
20760 KB |
Output isn't correct |
39 |
Incorrect |
61 ms |
20968 KB |
Output isn't correct |
40 |
Incorrect |
56 ms |
20804 KB |
Output isn't correct |
41 |
Incorrect |
53 ms |
20520 KB |
Output isn't correct |
42 |
Correct |
47 ms |
19424 KB |
Output is correct |
43 |
Correct |
45 ms |
19364 KB |
Output is correct |
44 |
Correct |
43 ms |
19276 KB |
Output is correct |
45 |
Correct |
150 ms |
37292 KB |
Output is correct |
46 |
Incorrect |
64 ms |
20508 KB |
Output isn't correct |
47 |
Incorrect |
64 ms |
21032 KB |
Output isn't correct |
48 |
Incorrect |
55 ms |
20628 KB |
Output isn't correct |
49 |
Incorrect |
58 ms |
20560 KB |
Output isn't correct |
50 |
Correct |
48 ms |
19436 KB |
Output is correct |
51 |
Correct |
46 ms |
19440 KB |
Output is correct |
52 |
Correct |
47 ms |
19376 KB |
Output is correct |
53 |
Correct |
161 ms |
36684 KB |
Output is correct |
54 |
Incorrect |
58 ms |
20700 KB |
Output isn't correct |