#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
const int mx = 100'000;
const int emx = 500'000;
vl c(1+mx);
vector<pii> edge[1+mx];
vi deg(1+mx, 0);
vi visit(1+emx, 0);
vector<ll> ans(1+emx);
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; i++) cin >> c[i];
for(int j = 1; j <= M; j++)
{
int u, v;
cin >> u >> v;
edge[u].push_back({v, j});
edge[v].push_back({u, j});
deg[u]++;
deg[v]++;
}
if(M > N)
{
cout << "0\n";
return 0;
}
queue<int> tbv;
for(int i = 1; i <= N; i++)
{
if(deg[i] == 1)
{
tbv.push(i);
}
}
int endv = -1;
while(!tbv.empty())
{
int u = tbv.front();
tbv.pop();
// cerr << "u = " << u << '\n';
int elim = 0;
for(auto ed: edge[u])
{
int v = ed.first;
if(visit[ed.second]) continue;
visit[ed.second] = 1;
deg[v]--;
elim = 1;
if(deg[v] <= 1)
{
tbv.push(v);
}
ans[ed.second] = 2*c[u];
// cerr << ed.first << ' ' << ed.second << " : " << 2*c[u] << '\n';
c[v] -= c[u];
c[u] -= c[u];
}
if(!elim)
{
if(M == N-1)
{
if(c[u] != 0)
{
cout << "0\n";
return 0;
}
}
}
}
for(int e = 1; e <= M; e++)
{
cout << ans[e] << '\n';
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:59:6: warning: unused variable 'endv' [-Wunused-variable]
59 | int endv = -1;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9680 KB |
Output is correct |
3 |
Correct |
5 ms |
9760 KB |
Output is correct |
4 |
Correct |
61 ms |
14008 KB |
Output is correct |
5 |
Correct |
4 ms |
9680 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9676 KB |
Output is correct |
8 |
Correct |
5 ms |
9680 KB |
Output is correct |
9 |
Correct |
5 ms |
9688 KB |
Output is correct |
10 |
Correct |
5 ms |
9680 KB |
Output is correct |
11 |
Correct |
5 ms |
9692 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
49 ms |
13156 KB |
Output is correct |
14 |
Correct |
74 ms |
13736 KB |
Output is correct |
15 |
Correct |
56 ms |
14076 KB |
Output is correct |
16 |
Correct |
47 ms |
13396 KB |
Output is correct |
17 |
Correct |
63 ms |
14076 KB |
Output is correct |
18 |
Correct |
79 ms |
14084 KB |
Output is correct |
19 |
Correct |
55 ms |
13344 KB |
Output is correct |
20 |
Correct |
4 ms |
9708 KB |
Output is correct |
21 |
Correct |
5 ms |
9676 KB |
Output is correct |
22 |
Correct |
64 ms |
14068 KB |
Output is correct |
23 |
Correct |
44 ms |
13104 KB |
Output is correct |
24 |
Correct |
57 ms |
14092 KB |
Output is correct |
25 |
Correct |
52 ms |
13252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9676 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
9676 KB |
Output isn't correct |
3 |
Incorrect |
52 ms |
13396 KB |
Output isn't correct |
4 |
Correct |
42 ms |
12964 KB |
Output is correct |
5 |
Correct |
38 ms |
13172 KB |
Output is correct |
6 |
Correct |
192 ms |
23484 KB |
Output is correct |
7 |
Incorrect |
5 ms |
9676 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
9676 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
9676 KB |
Output isn't correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
6 ms |
9676 KB |
Output is correct |
12 |
Correct |
7 ms |
9680 KB |
Output is correct |
13 |
Correct |
6 ms |
9676 KB |
Output is correct |
14 |
Incorrect |
6 ms |
9676 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
9676 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
9676 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
9676 KB |
Output isn't correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
7 ms |
9692 KB |
Output is correct |
20 |
Correct |
4 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9812 KB |
Output is correct |
22 |
Incorrect |
6 ms |
9684 KB |
Output isn't correct |
23 |
Incorrect |
39 ms |
12708 KB |
Output isn't correct |
24 |
Incorrect |
51 ms |
13420 KB |
Output isn't correct |
25 |
Incorrect |
51 ms |
13468 KB |
Output isn't correct |
26 |
Correct |
41 ms |
12912 KB |
Output is correct |
27 |
Correct |
42 ms |
12852 KB |
Output is correct |
28 |
Correct |
47 ms |
13252 KB |
Output is correct |
29 |
Correct |
132 ms |
20888 KB |
Output is correct |
30 |
Incorrect |
61 ms |
13096 KB |
Output isn't correct |
31 |
Incorrect |
61 ms |
13196 KB |
Output isn't correct |
32 |
Incorrect |
66 ms |
13844 KB |
Output isn't correct |
33 |
Incorrect |
54 ms |
13452 KB |
Output isn't correct |
34 |
Correct |
45 ms |
12876 KB |
Output is correct |
35 |
Correct |
43 ms |
12956 KB |
Output is correct |
36 |
Correct |
41 ms |
13168 KB |
Output is correct |
37 |
Correct |
156 ms |
23504 KB |
Output is correct |
38 |
Incorrect |
64 ms |
13284 KB |
Output isn't correct |
39 |
Incorrect |
64 ms |
14020 KB |
Output isn't correct |
40 |
Incorrect |
56 ms |
13504 KB |
Output isn't correct |
41 |
Incorrect |
73 ms |
13152 KB |
Output isn't correct |
42 |
Correct |
53 ms |
12796 KB |
Output is correct |
43 |
Correct |
37 ms |
12748 KB |
Output is correct |
44 |
Correct |
37 ms |
13172 KB |
Output is correct |
45 |
Correct |
159 ms |
22084 KB |
Output is correct |
46 |
Incorrect |
66 ms |
13108 KB |
Output isn't correct |
47 |
Incorrect |
70 ms |
13484 KB |
Output isn't correct |
48 |
Incorrect |
78 ms |
13092 KB |
Output isn't correct |
49 |
Incorrect |
51 ms |
13740 KB |
Output isn't correct |
50 |
Correct |
43 ms |
13036 KB |
Output is correct |
51 |
Correct |
41 ms |
13296 KB |
Output is correct |
52 |
Correct |
38 ms |
13192 KB |
Output is correct |
53 |
Correct |
149 ms |
21708 KB |
Output is correct |
54 |
Incorrect |
61 ms |
13764 KB |
Output isn't correct |