# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
245294 |
2020-07-06T01:01:50 Z |
super_j6 |
Pipes (BOI13_pipes) |
C++14 |
|
118 ms |
20100 KB |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 500000;
int n, m, k;
pi e[mxn];
int a[mxn], d[mxn], vis[mxn];
vector<int> s;
vector<int> g[mxn];
stack<int> stk;
int ans[mxn];
void die(){
cout << 0 << endl;
exit(0);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
if(m > n) die();
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++){
cin >> e[i].f >> e[i].s;
d[--e[i].f]++, d[--e[i].s]++;
g[e[i].f].push_back(i);
g[e[i].s].push_back(i);
}
for(int i = 0; i < n; i++) if(!~-d[i]) stk.push(i);
while(!stk.empty()){
int c = stk.top();
stk.pop();
for(int i : g[c]){
if(!vis[i]){
int v = c ^ e[i].f ^ e[i].s;
d[v]--;
a[v] -= a[c];
vis[i] = 1;
ans[i] = 2 * a[c];
if(!~-d[v]) stk.push(v);
}
}
}
for(int i = 0; i < m; i++){
if(!vis[i]){
for(int j = e[i].f;;){
bool t = 0;
for(int l : g[j]){
if(!vis[l]){
t = vis[l] = 1;
if(j != e[l].f) swap(e[l].f, e[l].s);
j = e[l].s;
s.push_back(l);
break;
}
}
if(!t) break;
}
}
}
k = s.size();
if(k && !(k & 1)) die();
for(int i = 0; i < k; i++) ans[s[0]] += (1 - 2 * (i & 1)) * a[e[s[i]].s];
for(int i = 1; i < k; i++) ans[s[i]] = 2 * a[e[s[i]].f] - ans[s[i - 1]];
for(int i = 0; i < m; i++) cout << ans[i] << endl;
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:66:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
t = vis[l] = 1;
~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
2 |
Correct |
13 ms |
12072 KB |
Output is correct |
3 |
Correct |
12 ms |
12160 KB |
Output is correct |
4 |
Correct |
91 ms |
19832 KB |
Output is correct |
5 |
Correct |
13 ms |
12160 KB |
Output is correct |
6 |
Correct |
12 ms |
12160 KB |
Output is correct |
7 |
Correct |
11 ms |
12160 KB |
Output is correct |
8 |
Correct |
12 ms |
12160 KB |
Output is correct |
9 |
Correct |
14 ms |
12160 KB |
Output is correct |
10 |
Correct |
12 ms |
12160 KB |
Output is correct |
11 |
Correct |
12 ms |
12160 KB |
Output is correct |
12 |
Correct |
13 ms |
12160 KB |
Output is correct |
13 |
Correct |
71 ms |
18296 KB |
Output is correct |
14 |
Correct |
97 ms |
19484 KB |
Output is correct |
15 |
Correct |
93 ms |
19960 KB |
Output is correct |
16 |
Correct |
93 ms |
18680 KB |
Output is correct |
17 |
Correct |
107 ms |
19960 KB |
Output is correct |
18 |
Correct |
97 ms |
19980 KB |
Output is correct |
19 |
Correct |
118 ms |
19704 KB |
Output is correct |
20 |
Correct |
13 ms |
12160 KB |
Output is correct |
21 |
Correct |
14 ms |
12160 KB |
Output is correct |
22 |
Correct |
93 ms |
19960 KB |
Output is correct |
23 |
Correct |
72 ms |
18296 KB |
Output is correct |
24 |
Correct |
95 ms |
19984 KB |
Output is correct |
25 |
Correct |
91 ms |
18552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
2 |
Correct |
12 ms |
12160 KB |
Output is correct |
3 |
Correct |
80 ms |
19300 KB |
Output is correct |
4 |
Correct |
15 ms |
12160 KB |
Output is correct |
5 |
Correct |
12 ms |
12160 KB |
Output is correct |
6 |
Correct |
15 ms |
12160 KB |
Output is correct |
7 |
Correct |
11 ms |
12160 KB |
Output is correct |
8 |
Correct |
12 ms |
12160 KB |
Output is correct |
9 |
Correct |
14 ms |
12160 KB |
Output is correct |
10 |
Correct |
12 ms |
12032 KB |
Output is correct |
11 |
Correct |
11 ms |
12032 KB |
Output is correct |
12 |
Correct |
11 ms |
12032 KB |
Output is correct |
13 |
Correct |
12 ms |
12032 KB |
Output is correct |
14 |
Correct |
14 ms |
12160 KB |
Output is correct |
15 |
Correct |
12 ms |
12288 KB |
Output is correct |
16 |
Correct |
12 ms |
12160 KB |
Output is correct |
17 |
Correct |
12 ms |
12160 KB |
Output is correct |
18 |
Correct |
12 ms |
12032 KB |
Output is correct |
19 |
Correct |
11 ms |
12032 KB |
Output is correct |
20 |
Correct |
13 ms |
12160 KB |
Output is correct |
21 |
Correct |
11 ms |
12160 KB |
Output is correct |
22 |
Correct |
15 ms |
12160 KB |
Output is correct |
23 |
Correct |
78 ms |
18548 KB |
Output is correct |
24 |
Correct |
90 ms |
20084 KB |
Output is correct |
25 |
Correct |
91 ms |
19320 KB |
Output is correct |
26 |
Correct |
12 ms |
12160 KB |
Output is correct |
27 |
Correct |
12 ms |
12160 KB |
Output is correct |
28 |
Correct |
11 ms |
12160 KB |
Output is correct |
29 |
Correct |
12 ms |
12160 KB |
Output is correct |
30 |
Correct |
101 ms |
19772 KB |
Output is correct |
31 |
Correct |
98 ms |
20092 KB |
Output is correct |
32 |
Correct |
93 ms |
20064 KB |
Output is correct |
33 |
Correct |
92 ms |
19576 KB |
Output is correct |
34 |
Correct |
12 ms |
12160 KB |
Output is correct |
35 |
Correct |
12 ms |
12032 KB |
Output is correct |
36 |
Correct |
11 ms |
12160 KB |
Output is correct |
37 |
Correct |
11 ms |
12032 KB |
Output is correct |
38 |
Correct |
84 ms |
19976 KB |
Output is correct |
39 |
Correct |
97 ms |
19832 KB |
Output is correct |
40 |
Correct |
95 ms |
20084 KB |
Output is correct |
41 |
Correct |
79 ms |
19840 KB |
Output is correct |
42 |
Correct |
11 ms |
12160 KB |
Output is correct |
43 |
Correct |
11 ms |
12032 KB |
Output is correct |
44 |
Correct |
11 ms |
12160 KB |
Output is correct |
45 |
Correct |
11 ms |
12032 KB |
Output is correct |
46 |
Correct |
104 ms |
19952 KB |
Output is correct |
47 |
Correct |
93 ms |
20084 KB |
Output is correct |
48 |
Correct |
91 ms |
20100 KB |
Output is correct |
49 |
Correct |
81 ms |
19064 KB |
Output is correct |
50 |
Correct |
11 ms |
12160 KB |
Output is correct |
51 |
Correct |
12 ms |
12160 KB |
Output is correct |
52 |
Correct |
12 ms |
12160 KB |
Output is correct |
53 |
Correct |
12 ms |
12160 KB |
Output is correct |
54 |
Correct |
91 ms |
19828 KB |
Output is correct |