# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
444697 |
2021-07-14T21:28:00 Z |
Aryan_Raina |
Pipes (BOI13_pipes) |
C++17 |
|
235 ms |
40248 KB |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define ld long double
#define ar array
#define all(a) a.begin(), a.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e15;
void solve() {
int N, M; cin >> N >> M;
vector<ar<int,2>> g[N];
vector<int> C(N), ans(M), degree(N, 0);
for (int &i : C) cin >> i;
for (int i = 0; i < M; i++) {
int u, v; cin >> u >> v;
--u, --v;
g[u].push_back({v, i});
g[v].push_back({u, i});
degree[u]++;
degree[v]++;
}
if (M > N) {
cout << "0\n";
return;
}
queue<int> q;
for (int i = 0; i < N; i++)
if (degree[i] == 1) q.push(i);
while (!q.empty()) {
int u = q.front(); q.pop();
for (auto [v,i] : g[u]) if (degree[v]) {
degree[v]--; degree[u]--;
C[v] -= (ans[i] = C[u]);
if (degree[v] == 1) q.push(v);
}
}
if (N-1 == M) {
for (int i : ans) cout << 2*i << '\n';
return;
}
vector<ar<int,2>> shit;
for (int x = 0; x < N; x++) if (degree[x] == 2) {
for (int u = x; u >= 0; ) {
int nex = -1;
for (auto [v,i] : g[u]) if (degree[v] == 2){
shit.push_back({v, i});
degree[v]--; degree[u]--;
nex = v;
break;
}
u = nex;
}
for (auto [v, i] : g[x]) if (degree[v] == 1) shit.push_back({x, i});
}
int lol = 0;
for (int i = 0; i < shit.size(); i++) {
if (i&1) lol -= C[shit[i][0]];
else lol += C[shit[i][0]];
}
if (!(shit.size()&1) || lol&1) {
cout << "0\n";
return;
}
lol /= 2;
for (int i = 0; i < shit.size(); i++) {
ans[shit[i][1]] = lol;
lol = C[shit[i][0]] - lol;
}
for (int i : ans) cout << 2*i << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while (t--) solve();
}
Compilation message
pipes.cpp: In function 'void solve()':
pipes.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::array<long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < shit.size(); i++) {
| ~~^~~~~~~~~~~~~
pipes.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::array<long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < shit.size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
73 ms |
12504 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
54 ms |
10012 KB |
Output is correct |
14 |
Correct |
66 ms |
11804 KB |
Output is correct |
15 |
Correct |
88 ms |
12480 KB |
Output is correct |
16 |
Correct |
76 ms |
10604 KB |
Output is correct |
17 |
Correct |
86 ms |
12440 KB |
Output is correct |
18 |
Correct |
77 ms |
12592 KB |
Output is correct |
19 |
Correct |
84 ms |
12172 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
77 ms |
12556 KB |
Output is correct |
23 |
Correct |
57 ms |
9972 KB |
Output is correct |
24 |
Correct |
72 ms |
12520 KB |
Output is correct |
25 |
Correct |
66 ms |
10468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
59 ms |
12264 KB |
Output is correct |
4 |
Correct |
55 ms |
11760 KB |
Output is correct |
5 |
Correct |
57 ms |
11404 KB |
Output is correct |
6 |
Correct |
231 ms |
40248 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
58 ms |
10952 KB |
Output is correct |
24 |
Correct |
77 ms |
13316 KB |
Output is correct |
25 |
Correct |
61 ms |
12292 KB |
Output is correct |
26 |
Correct |
62 ms |
11716 KB |
Output is correct |
27 |
Correct |
51 ms |
11600 KB |
Output is correct |
28 |
Correct |
52 ms |
12112 KB |
Output is correct |
29 |
Correct |
191 ms |
33024 KB |
Output is correct |
30 |
Correct |
78 ms |
12724 KB |
Output is correct |
31 |
Correct |
86 ms |
13884 KB |
Output is correct |
32 |
Correct |
81 ms |
12752 KB |
Output is correct |
33 |
Correct |
109 ms |
13016 KB |
Output is correct |
34 |
Correct |
57 ms |
11680 KB |
Output is correct |
35 |
Correct |
58 ms |
11788 KB |
Output is correct |
36 |
Correct |
56 ms |
11844 KB |
Output is correct |
37 |
Correct |
235 ms |
40248 KB |
Output is correct |
38 |
Correct |
81 ms |
13024 KB |
Output is correct |
39 |
Correct |
79 ms |
12576 KB |
Output is correct |
40 |
Correct |
77 ms |
13096 KB |
Output is correct |
41 |
Correct |
67 ms |
13884 KB |
Output is correct |
42 |
Correct |
52 ms |
11672 KB |
Output is correct |
43 |
Correct |
57 ms |
11632 KB |
Output is correct |
44 |
Correct |
63 ms |
11332 KB |
Output is correct |
45 |
Correct |
170 ms |
34756 KB |
Output is correct |
46 |
Correct |
83 ms |
12876 KB |
Output is correct |
47 |
Correct |
85 ms |
13136 KB |
Output is correct |
48 |
Correct |
94 ms |
13864 KB |
Output is correct |
49 |
Correct |
66 ms |
11540 KB |
Output is correct |
50 |
Correct |
55 ms |
11792 KB |
Output is correct |
51 |
Correct |
58 ms |
11668 KB |
Output is correct |
52 |
Correct |
81 ms |
11580 KB |
Output is correct |
53 |
Correct |
195 ms |
34768 KB |
Output is correct |
54 |
Correct |
83 ms |
12824 KB |
Output is correct |