# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
319020 |
2020-11-03T17:49:35 Z |
rqi |
Pipes (BOI13_pipes) |
C++14 |
|
378 ms |
21988 KB |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define mp make_pair
#define f first
#define s second
#define pb push_back
struct DSU{
vi e;
void init(int n){
e = vi(n, -1);
}
int get(int a){
if(e[a] < 0) return a;
e[a] = get(e[a]);
return e[a];
}
bool unite(int a, int b){
a = get(a);
b = get(b);
if(a == b) return 0;
if(-e[a] < -e[b]) swap(a, b);
e[b] = a;
return 1;
}
};
const int mx = 500005;
const int mx1 = 100005;
int N, M;
ll c[mx1];
int u[mx];
int v[mx];
ll x[mx];
bool inTree[mx1];
vpi adj[mx1];
int depth[mx1];
void genTree(int node, int prv = -1, int d = 0){
depth[node] = d;
for(auto u: adj[node]){
if(u.f == prv) continue;
genTree(u.f, node, d+1);
ll val = c[u.f];
x[u.s]+=val;
c[u.f]-=val;
c[node]-=val;
}
}
int main(){
cin >> N >> M;
DSU dsu;
dsu.init(N+5);
for(int i = 1; i <= N; i++){
cin >> c[i];
}
for(int i = 1; i <= M; i++){
cin >> u[i] >> v[i];
if(dsu.unite(u[i], v[i])){
inTree[i] = 1;
adj[u[i]].pb(mp(v[i], i));
adj[v[i]].pb(mp(u[i], i));
}
}
genTree(1);
if(M == N-1){
if(c[1] != 0){
cout << 0 << "\n";
return 0;
}
for(int i = 1; i <= M; i++){
cout << 2*x[i] << "\n";
}
return 0;
}
if(M >= N+1){
cout << 0 << "\n";
return 0;
}
for(int i = 1; i <= M; i++){
if(inTree[i]) continue;
if(depth[u[i]] % 2 != depth[v[i]] % 2){
cout << 0 << "\n";
return 0;
}
}
for(int i = 1; i <= M; i++){
cout << 2*x[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
142 ms |
11672 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
3 ms |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
2796 KB |
Output is correct |
11 |
Correct |
4 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2796 KB |
Output is correct |
13 |
Correct |
111 ms |
9960 KB |
Output is correct |
14 |
Correct |
130 ms |
11236 KB |
Output is correct |
15 |
Correct |
143 ms |
11748 KB |
Output is correct |
16 |
Correct |
116 ms |
10340 KB |
Output is correct |
17 |
Correct |
143 ms |
11752 KB |
Output is correct |
18 |
Correct |
139 ms |
11748 KB |
Output is correct |
19 |
Correct |
145 ms |
15720 KB |
Output is correct |
20 |
Correct |
2 ms |
2668 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
137 ms |
11620 KB |
Output is correct |
23 |
Correct |
105 ms |
9828 KB |
Output is correct |
24 |
Correct |
142 ms |
11772 KB |
Output is correct |
25 |
Correct |
114 ms |
10424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2668 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
3 |
Correct |
122 ms |
13368 KB |
Output is correct |
4 |
Correct |
134 ms |
14180 KB |
Output is correct |
5 |
Correct |
123 ms |
11108 KB |
Output is correct |
6 |
Correct |
375 ms |
21860 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2668 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2796 KB |
Output isn't correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
3 ms |
2668 KB |
Output is correct |
14 |
Incorrect |
2 ms |
2668 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
2828 KB |
Output isn't correct |
17 |
Correct |
3 ms |
2796 KB |
Output is correct |
18 |
Correct |
3 ms |
2796 KB |
Output is correct |
19 |
Correct |
3 ms |
2796 KB |
Output is correct |
20 |
Correct |
3 ms |
2796 KB |
Output is correct |
21 |
Correct |
4 ms |
2796 KB |
Output is correct |
22 |
Incorrect |
3 ms |
2796 KB |
Output isn't correct |
23 |
Incorrect |
114 ms |
12772 KB |
Output isn't correct |
24 |
Incorrect |
146 ms |
15208 KB |
Output isn't correct |
25 |
Correct |
122 ms |
13284 KB |
Output is correct |
26 |
Correct |
132 ms |
16484 KB |
Output is correct |
27 |
Correct |
132 ms |
16996 KB |
Output is correct |
28 |
Correct |
133 ms |
11236 KB |
Output is correct |
29 |
Correct |
318 ms |
19688 KB |
Output is correct |
30 |
Incorrect |
148 ms |
18668 KB |
Output isn't correct |
31 |
Incorrect |
144 ms |
18024 KB |
Output isn't correct |
32 |
Incorrect |
141 ms |
12776 KB |
Output isn't correct |
33 |
Correct |
134 ms |
14692 KB |
Output is correct |
34 |
Correct |
134 ms |
15848 KB |
Output is correct |
35 |
Correct |
129 ms |
14048 KB |
Output is correct |
36 |
Correct |
128 ms |
11152 KB |
Output is correct |
37 |
Correct |
378 ms |
21988 KB |
Output is correct |
38 |
Incorrect |
146 ms |
14560 KB |
Output isn't correct |
39 |
Incorrect |
140 ms |
12428 KB |
Output isn't correct |
40 |
Incorrect |
144 ms |
14440 KB |
Output isn't correct |
41 |
Correct |
134 ms |
18020 KB |
Output is correct |
42 |
Correct |
132 ms |
18148 KB |
Output is correct |
43 |
Correct |
132 ms |
15336 KB |
Output is correct |
44 |
Correct |
128 ms |
11108 KB |
Output is correct |
45 |
Correct |
300 ms |
16740 KB |
Output is correct |
46 |
Incorrect |
146 ms |
16832 KB |
Output isn't correct |
47 |
Incorrect |
151 ms |
14820 KB |
Output isn't correct |
48 |
Incorrect |
150 ms |
18692 KB |
Output isn't correct |
49 |
Correct |
122 ms |
11876 KB |
Output is correct |
50 |
Correct |
135 ms |
15204 KB |
Output is correct |
51 |
Correct |
128 ms |
13028 KB |
Output is correct |
52 |
Correct |
127 ms |
12260 KB |
Output is correct |
53 |
Correct |
318 ms |
18276 KB |
Output is correct |
54 |
Incorrect |
144 ms |
16100 KB |
Output isn't correct |