# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111251 |
2024-11-11T20:46:39 Z |
codexistent |
Pipes (BOI13_pipes) |
C++14 |
|
299 ms |
48200 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 100005
#define MAXM 500005
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
#define f first
#define s second
ll n, m, t[MAXN], en[MAXN], r[MAXM];
pair<ll, ll> e[MAXM];
vector<pair<ll, ll>> adj[MAXN];
bool v[MAXN];
int main(){
cin >> n >> m;
FOR(i, 1, n) {
cin >> t[i];
en[i] = 0, v[i] = false;
}
FOR(i, 1, m){
cin >> e[i].f >> e[i].s;
adj[e[i].f].push_back({e[i].s, i}), en[e[i].f]++;
adj[e[i].s].push_back({e[i].f, i}), en[e[i].s]++;
r[i] = 1000000001;
}
if(!(m == n - 1 || m == n)) return cout << 0 << endl, 0;
queue<ll> q;
FOR(i, 1, n) if(en[i] == 1) q.push(i);
ll d = n;
while(q.size()){
ll qi = q.front(); q.pop();
if(v[qi]) continue;
v[qi] = true, d--;
if(en[qi] == 0) continue;
for(pair<ll, ll> p : adj[qi]) if(r[p.s] == 1000000001) {
r[p.s] = 2 * t[qi];
t[p.f] -= t[qi], en[p.f]--;
if(!v[p.f] && en[p.f] == 1) q.push(p.f);
}
}
if(d != 0 && d % 2 == 0) return cout << 0 << endl, 0;
ll stt, ci = -1;
FOR(i, 1, n) if(!v[i]) ci = i;
if(ci == -1) {
FOR(i, 1, m) cout << r[i] << endl;
return 0;
}
stt = ci;
stack<ll> st;
ll alts = 0;
do{
for(pair<ll, ll> p : adj[ci]) if(r[p.s] != 1000000001) {
alts = p.s + (-1)*(alts);
ci = p.f;
break;
}
st.push(ci);
}while(stt != ci);
ll prvi;
for(pair<ll, ll> p : adj[stt]) if(r[p.s] != 1000000001) {
prvi = r[p.s] = t[stt] - alts;
if(prvi % 2) return cout << 0 << endl, 0;
}
st.pop();
while(!st.empty()){
ll sti = st.top(); st.pop();
for(pair<ll, ll> p : adj[sti]) if(e[p.s].f == prvi || e[p.s].s == prvi) {
prvi = r[p.s] = 2 * (r[sti] - prvi / 2);
if(prvi % 2) return cout << 0 << endl, 0;
}
}
FOR(i, 1, m) cout << r[i] << endl;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:78:60: warning: 'prvi' may be used uninitialized in this function [-Wmaybe-uninitialized]
78 | for(pair<ll, ll> p : adj[sti]) if(e[p.s].f == prvi || e[p.s].s == prvi) {
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2896 KB |
Output is correct |
4 |
Correct |
238 ms |
14164 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
3 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
4 ms |
2896 KB |
Output is correct |
10 |
Correct |
4 ms |
2896 KB |
Output is correct |
11 |
Correct |
4 ms |
2896 KB |
Output is correct |
12 |
Correct |
4 ms |
2896 KB |
Output is correct |
13 |
Correct |
164 ms |
11848 KB |
Output is correct |
14 |
Correct |
203 ms |
13656 KB |
Output is correct |
15 |
Correct |
207 ms |
14152 KB |
Output is correct |
16 |
Correct |
175 ms |
12616 KB |
Output is correct |
17 |
Correct |
230 ms |
14152 KB |
Output is correct |
18 |
Correct |
211 ms |
14164 KB |
Output is correct |
19 |
Correct |
221 ms |
14072 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
4 ms |
2896 KB |
Output is correct |
22 |
Correct |
236 ms |
14284 KB |
Output is correct |
23 |
Correct |
173 ms |
11848 KB |
Output is correct |
24 |
Correct |
232 ms |
14448 KB |
Output is correct |
25 |
Correct |
179 ms |
12248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
2896 KB |
Output isn't correct |
3 |
Correct |
66 ms |
13128 KB |
Output is correct |
4 |
Correct |
77 ms |
13392 KB |
Output is correct |
5 |
Correct |
65 ms |
13144 KB |
Output is correct |
6 |
Correct |
266 ms |
48200 KB |
Output is correct |
7 |
Incorrect |
3 ms |
2804 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2604 KB |
Output isn't correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2808 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
3 ms |
2804 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Incorrect |
3 ms |
2640 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
2896 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
2896 KB |
Output isn't correct |
17 |
Correct |
3 ms |
2896 KB |
Output is correct |
18 |
Correct |
3 ms |
2808 KB |
Output is correct |
19 |
Correct |
3 ms |
3112 KB |
Output is correct |
20 |
Correct |
3 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2896 KB |
Output is correct |
22 |
Incorrect |
4 ms |
2896 KB |
Output isn't correct |
23 |
Incorrect |
182 ms |
12360 KB |
Output isn't correct |
24 |
Incorrect |
233 ms |
14644 KB |
Output isn't correct |
25 |
Correct |
77 ms |
13128 KB |
Output is correct |
26 |
Correct |
68 ms |
13384 KB |
Output is correct |
27 |
Correct |
64 ms |
13388 KB |
Output is correct |
28 |
Correct |
74 ms |
13896 KB |
Output is correct |
29 |
Correct |
237 ms |
39496 KB |
Output is correct |
30 |
Incorrect |
210 ms |
14124 KB |
Output isn't correct |
31 |
Incorrect |
218 ms |
14408 KB |
Output isn't correct |
32 |
Incorrect |
214 ms |
14152 KB |
Output isn't correct |
33 |
Correct |
68 ms |
13592 KB |
Output is correct |
34 |
Correct |
68 ms |
13528 KB |
Output is correct |
35 |
Correct |
66 ms |
13384 KB |
Output is correct |
36 |
Correct |
65 ms |
13648 KB |
Output is correct |
37 |
Correct |
299 ms |
48200 KB |
Output is correct |
38 |
Incorrect |
216 ms |
14412 KB |
Output isn't correct |
39 |
Incorrect |
219 ms |
14152 KB |
Output isn't correct |
40 |
Incorrect |
222 ms |
14464 KB |
Output isn't correct |
41 |
Correct |
77 ms |
13444 KB |
Output is correct |
42 |
Correct |
68 ms |
13504 KB |
Output is correct |
43 |
Correct |
65 ms |
13304 KB |
Output is correct |
44 |
Correct |
62 ms |
13128 KB |
Output is correct |
45 |
Correct |
211 ms |
42824 KB |
Output is correct |
46 |
Incorrect |
213 ms |
14056 KB |
Output isn't correct |
47 |
Incorrect |
220 ms |
14500 KB |
Output isn't correct |
48 |
Incorrect |
204 ms |
14552 KB |
Output isn't correct |
49 |
Correct |
81 ms |
13132 KB |
Output is correct |
50 |
Correct |
76 ms |
13384 KB |
Output is correct |
51 |
Correct |
74 ms |
13392 KB |
Output is correct |
52 |
Correct |
69 ms |
13384 KB |
Output is correct |
53 |
Correct |
221 ms |
42824 KB |
Output is correct |
54 |
Incorrect |
223 ms |
14152 KB |
Output isn't correct |