# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631402 |
2022-08-18T05:34:09 Z |
socpite |
Pipes (BOI13_pipes) |
C++14 |
|
115 ms |
131072 KB |
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
const int maxn = 1e5+5;
typedef long long ll;
ll lim = 1;
int _s, _t;
int n, m;
vector<int> idx, vert;
int vis[maxn], oncyc[maxn];
ll val[maxn], ans[maxn], A[maxn];
vector<pair<int, int>> graph[maxn];
void find_ep(int x, int p){
vis[x]=1;
for(auto v: graph[x]){
if(v.f == p)continue;
if(vis[v.f]){
if(!_s){
_s = x;
_t = v.f;
idx.push_back(v.s);
}
}
else find_ep(v.f, x);
}
}
void find_cyc(int x, int p){
if(x == _t)oncyc[x]=1;
else{
for(auto v: graph[x]){
if(v.f == p || (x == _s && v.f == _t) || (x == _t && v.f == _s))continue;
find_cyc(v.f, x);
if(oncyc[v.f]){
idx.push_back(v.s);
oncyc[x]=1;
}
}
}
if(oncyc[x])vert.push_back(x);
}
void solve(int x, int p){
for(auto v: graph[x]){
if(v.f == p || oncyc[v.f])continue;
solve(v.f, p);
ans[v.s]=val[v.f];
val[x]-=val[v.f];
}
}
void dfs(int x, int p){
//cout << x << endl;
for(auto v: graph[x]){
if(v.f == p)continue;
dfs(v.f, x);
ans[v.s]=val[v.f];
val[x]-=val[v.f];
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
if(m > n){
cout << 0;
return 0;
}
for(int i = 1; i <= n; i++)cin >> val[i];
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
graph[a].push_back({b, i});
graph[b].push_back({a, i});
}
if(m == n){
find_ep(1, 0);
find_cyc(_s, 0);
if(!(vert.size()&1)){
cout << 0;
return 0;
}
ll sum = 0;
for(auto v: vert){
solve(v, 0);
sum += val[v];
}
sum/=2;
for(int i = 1; i < vert.size(); i+=2)sum-=val[vert[i]];
ans[idx[0]] = sum;
for(int i = 1; i < idx.size(); i++)ans[idx[i]] = val[vert[i-1]]-ans[idx[i-1]];
}
else{
dfs(1, 0);
}
for(int i = 1; i <= m; i++)cout << ans[i]*2 << "\n";
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:100:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i = 1; i < vert.size(); i+=2)sum-=val[vert[i]];
| ~~^~~~~~~~~~~~~
pipes.cpp:102:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int i = 1; i < idx.size(); i++)ans[idx[i]] = val[vert[i-1]]-ans[idx[i-1]];
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
50 ms |
8372 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2772 KB |
Output is correct |
13 |
Correct |
37 ms |
7124 KB |
Output is correct |
14 |
Correct |
44 ms |
8048 KB |
Output is correct |
15 |
Correct |
48 ms |
8316 KB |
Output is correct |
16 |
Correct |
40 ms |
7536 KB |
Output is correct |
17 |
Correct |
49 ms |
8312 KB |
Output is correct |
18 |
Correct |
48 ms |
8300 KB |
Output is correct |
19 |
Correct |
52 ms |
11660 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
48 ms |
8308 KB |
Output is correct |
23 |
Correct |
39 ms |
7128 KB |
Output is correct |
24 |
Correct |
48 ms |
8364 KB |
Output is correct |
25 |
Correct |
42 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Runtime error |
61 ms |
131072 KB |
Execution killed with signal 9 |
3 |
Correct |
52 ms |
11472 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Runtime error |
66 ms |
131072 KB |
Execution killed with signal 9 |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Runtime error |
60 ms |
131072 KB |
Execution killed with signal 9 |
15 |
Runtime error |
61 ms |
131072 KB |
Execution killed with signal 9 |
16 |
Runtime error |
59 ms |
131072 KB |
Execution killed with signal 9 |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Runtime error |
63 ms |
131072 KB |
Execution killed with signal 9 |
23 |
Runtime error |
98 ms |
131072 KB |
Execution killed with signal 9 |
24 |
Runtime error |
105 ms |
131072 KB |
Execution killed with signal 9 |
25 |
Correct |
49 ms |
11464 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Runtime error |
104 ms |
131072 KB |
Execution killed with signal 9 |
31 |
Runtime error |
115 ms |
131072 KB |
Execution killed with signal 9 |
32 |
Runtime error |
104 ms |
131072 KB |
Execution killed with signal 9 |
33 |
Correct |
49 ms |
12468 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Runtime error |
111 ms |
131072 KB |
Execution killed with signal 9 |
39 |
Runtime error |
102 ms |
131072 KB |
Execution killed with signal 9 |
40 |
Runtime error |
100 ms |
131072 KB |
Execution killed with signal 9 |
41 |
Correct |
57 ms |
15176 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Runtime error |
113 ms |
131072 KB |
Execution killed with signal 9 |
47 |
Runtime error |
108 ms |
131072 KB |
Execution killed with signal 9 |
48 |
Runtime error |
111 ms |
131072 KB |
Execution killed with signal 9 |
49 |
Correct |
45 ms |
8908 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2644 KB |
Output is correct |
54 |
Runtime error |
102 ms |
131072 KB |
Execution killed with signal 9 |