# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
251542 |
2020-07-21T18:58:33 Z |
abacaba |
Pipes (BOI13_pipes) |
C++14 |
|
262 ms |
29176 KB |
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 5e5 + 15;
int n, m, a[N];
vector <int> g[N];
bool used[N];
set <pii> cur;
int deg[N], d[N];
int p[N], sz[N];
pii e[N];
int ans[N];
int find(int v) {
if(v == p[v])
return v;
return p[v] = find(p[v]);
}
void unio(int a, int b) {
a = find(a);
b = find(b);
if(a != b) {
if(sz[a] < sz[b])
swap(a, b);
p[b] = a;
sz[a] += sz[b];
}
}
inline int gt(int i, int v) {
return e[i].f == v ? e[i].se : e[i].f;
}
void precheck(int v, int p = -1) {
used[v] = true;
for(int ind : g[v]) {
int to = gt(ind, v);
if(to == p)
continue;
if(used[to]) {
if(d[to] > d[v])
continue;
if((d[v] - d[to]) & 1) {
cout << 0 << endl;
exit(0);
}
}
else {
d[to] = d[v] + 1;
precheck(to, v);
}
}
}
main() {
for(int i = 1; i <= n; ++i)
p[i] = i, sz[i] = 1;
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
// setin("input.txt");
cin >> n >> m;
for(int i = 1; i <= n; ++i)
cin >> a[i];
for(int i = 1; i <= m; ++i) {
cin >> e[i].f >> e[i].se;
g[e[i].f].pb(i);
g[e[i].se].pb(i);
}
precheck(1);
for(int i = 1; i <= n; ++i)
deg[i] = g[i].size(), cur.insert({g[i].size(), i});
memset(used, 0, sizeof(used));
while(!cur.empty()) {
int v = cur.begin()->se;
if(deg[v] != 1)
break;
cur.erase(cur.begin());
used[v] = true;
for(int ind : g[v]) {
int to = gt(ind, v);
if(used[to])
a[v] -= ans[ind] / 2;
}
for(int ind : g[v]) {
int to = gt(ind, v);
if(used[to])
continue;
ans[ind] = 2 * a[v];
cur.erase({deg[to], to});
--deg[to];
cur.insert({deg[to], to});
}
}
for(int i = 1; i <= m; ++i)
cout << ans[i] << endl;
return 0;
}
Compilation message
pipes.cpp:117:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12672 KB |
Output is correct |
2 |
Correct |
8 ms |
12672 KB |
Output is correct |
3 |
Correct |
9 ms |
12672 KB |
Output is correct |
4 |
Correct |
199 ms |
23288 KB |
Output is correct |
5 |
Correct |
8 ms |
12544 KB |
Output is correct |
6 |
Correct |
7 ms |
12672 KB |
Output is correct |
7 |
Correct |
8 ms |
12544 KB |
Output is correct |
8 |
Correct |
8 ms |
12672 KB |
Output is correct |
9 |
Correct |
9 ms |
12672 KB |
Output is correct |
10 |
Correct |
8 ms |
12672 KB |
Output is correct |
11 |
Correct |
8 ms |
12672 KB |
Output is correct |
12 |
Correct |
9 ms |
12800 KB |
Output is correct |
13 |
Correct |
134 ms |
21172 KB |
Output is correct |
14 |
Correct |
161 ms |
22776 KB |
Output is correct |
15 |
Correct |
191 ms |
23288 KB |
Output is correct |
16 |
Correct |
177 ms |
21752 KB |
Output is correct |
17 |
Correct |
220 ms |
23288 KB |
Output is correct |
18 |
Correct |
177 ms |
23288 KB |
Output is correct |
19 |
Correct |
173 ms |
26360 KB |
Output is correct |
20 |
Correct |
8 ms |
12544 KB |
Output is correct |
21 |
Correct |
9 ms |
12672 KB |
Output is correct |
22 |
Correct |
184 ms |
23384 KB |
Output is correct |
23 |
Correct |
132 ms |
21112 KB |
Output is correct |
24 |
Correct |
214 ms |
23288 KB |
Output is correct |
25 |
Correct |
165 ms |
21752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12544 KB |
Output isn't correct |
2 |
Incorrect |
8 ms |
12800 KB |
Output isn't correct |
3 |
Correct |
64 ms |
19452 KB |
Output is correct |
4 |
Incorrect |
146 ms |
27768 KB |
Output isn't correct |
5 |
Incorrect |
174 ms |
23144 KB |
Output isn't correct |
6 |
Correct |
262 ms |
24568 KB |
Output is correct |
7 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
12672 KB |
Output isn't correct |
9 |
Correct |
9 ms |
12160 KB |
Output is correct |
10 |
Incorrect |
10 ms |
12672 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
12544 KB |
Output isn't correct |
12 |
Incorrect |
10 ms |
12544 KB |
Output isn't correct |
13 |
Correct |
7 ms |
12160 KB |
Output is correct |
14 |
Incorrect |
9 ms |
12544 KB |
Output isn't correct |
15 |
Incorrect |
8 ms |
12800 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
12672 KB |
Output isn't correct |
17 |
Correct |
9 ms |
12160 KB |
Output is correct |
18 |
Incorrect |
8 ms |
12672 KB |
Output isn't correct |
19 |
Incorrect |
8 ms |
12800 KB |
Output isn't correct |
20 |
Incorrect |
10 ms |
12672 KB |
Output isn't correct |
21 |
Correct |
8 ms |
12160 KB |
Output is correct |
22 |
Incorrect |
10 ms |
12800 KB |
Output isn't correct |
23 |
Incorrect |
99 ms |
24440 KB |
Output isn't correct |
24 |
Incorrect |
175 ms |
26488 KB |
Output isn't correct |
25 |
Correct |
79 ms |
19448 KB |
Output is correct |
26 |
Incorrect |
148 ms |
27156 KB |
Output isn't correct |
27 |
Incorrect |
142 ms |
27512 KB |
Output isn't correct |
28 |
Incorrect |
201 ms |
23288 KB |
Output isn't correct |
29 |
Correct |
207 ms |
22520 KB |
Output is correct |
30 |
Incorrect |
184 ms |
28408 KB |
Output isn't correct |
31 |
Incorrect |
139 ms |
28408 KB |
Output isn't correct |
32 |
Incorrect |
189 ms |
24440 KB |
Output isn't correct |
33 |
Correct |
89 ms |
20344 KB |
Output is correct |
34 |
Incorrect |
146 ms |
26592 KB |
Output isn't correct |
35 |
Incorrect |
118 ms |
27768 KB |
Output isn't correct |
36 |
Incorrect |
165 ms |
23288 KB |
Output isn't correct |
37 |
Correct |
199 ms |
24568 KB |
Output is correct |
38 |
Incorrect |
141 ms |
27768 KB |
Output isn't correct |
39 |
Incorrect |
168 ms |
23928 KB |
Output isn't correct |
40 |
Incorrect |
143 ms |
26232 KB |
Output isn't correct |
41 |
Correct |
74 ms |
22392 KB |
Output is correct |
42 |
Incorrect |
104 ms |
26872 KB |
Output isn't correct |
43 |
Incorrect |
102 ms |
28152 KB |
Output isn't correct |
44 |
Incorrect |
163 ms |
23288 KB |
Output isn't correct |
45 |
Correct |
162 ms |
22520 KB |
Output is correct |
46 |
Incorrect |
145 ms |
29176 KB |
Output isn't correct |
47 |
Incorrect |
141 ms |
26340 KB |
Output isn't correct |
48 |
Incorrect |
115 ms |
28280 KB |
Output isn't correct |
49 |
Correct |
58 ms |
17656 KB |
Output is correct |
50 |
Incorrect |
175 ms |
26616 KB |
Output isn't correct |
51 |
Incorrect |
141 ms |
25080 KB |
Output isn't correct |
52 |
Incorrect |
146 ms |
24568 KB |
Output isn't correct |
53 |
Correct |
177 ms |
22776 KB |
Output is correct |
54 |
Incorrect |
166 ms |
27348 KB |
Output isn't correct |