# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1053811 |
2024-08-11T17:54:22 Z |
codexistent |
Pipes (BOI13_pipes) |
C++14 |
|
497 ms |
100040 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, w[MAXN], d[MAXM];
set<ll> adj[MAXN];
pair<ll, pair<ll, ll>> e[MAXM];
bool v[MAXM];
map<pair<ll, ll>, ll> eid;
int main(){
cin >> n >> m;
FOR(i, 1, n) cin >> w[i];
FOR(i, 1, m){
e[i].f = 0;
cin >> e[i].s.f >> e[i].s.s;
adj[e[i].s.f].insert(e[i].s.s), adj[e[i].s.s].insert(e[i].s.f);
eid.insert({{min(e[i].s.f, e[i].s.s), max(e[i].s.f, e[i].s.s)}, i});
}
priority_queue<pair<ll, ll>> pq;
FOR(i, 1, m) {
v[i] = false;
e[i].f = adj[e[i].s.f].size() + adj[e[i].s.s].size() - 2;
//cout << "FOR EDGE " << i << " WE HAVE " << e[i].f << " CT " << endl;
for(auto j : adj[e[i].s.f]){
if(j != e[i].s.s && adj[j].size() == 2 && adj[e[i].s.s].find(j) != adj[e[i].s.s].end()){
e[i].f -= 2;
}
}
if(e[i].f == 0){
pq.push({0, i});
} else if(adj[e[i].s.f].size() == 1 || adj[e[i].s.s].size() == 1){
pq.push({1, i});
}
}
while(pq.size()){
//cout << pq.top().f << " ~ " << pq.top().s << " ==> " << e[pq.top().s].f << endl;
auto pqi = pq.top(); pq.pop();
if(v[pqi.s]) continue;
v[pqi.s] = true;
if(pqi.f == 0){
ll s = 0;
for(ll i2 : adj[e[pqi.s].s.f]) s += w[i2];
for(ll i2 : adj[e[pqi.s].s.s]) s += w[i2];
d[pqi.s] = w[e[pqi.s].s.f] + w[e[pqi.s].s.s] - s;
}else if(adj[e[pqi.s].s.f].size() == 1){
d[pqi.s] = w[e[pqi.s].s.f] * 2;
}else{
d[pqi.s] = w[e[pqi.s].s.s] * 2;
}
adj[e[pqi.s].s.f].erase(e[pqi.s].s.s);
adj[e[pqi.s].s.s].erase(e[pqi.s].s.f);
w[e[pqi.s].s.f] -= d[pqi.s] / 2;
w[e[pqi.s].s.s] -= d[pqi.s] / 2;
if(adj[e[pqi.s].s.f].size() == 2){
ll a = *(adj[e[pqi.s].s.f].begin());
ll b = *next(adj[e[pqi.s].s.f].begin(), 1);
if(eid.find({min(a, b), max(a, b)}) != eid.end()){
e[eid[{min(a, b), max(a, b)}]].f -= 2;
if(!v[eid[{min(a, b), max(a, b)}]] && e[eid[{min(a, b), max(a, b)}]].f == 0){
pq.push({0, eid[{min(a, b), max(a, b)}]});
}
}
}else if(adj[e[pqi.s].s.f].size() == 1){
ll a = *(adj[e[pqi.s].s.f].begin());
if(!v[eid[{min(a, e[pqi.s].s.f), max(a, e[pqi.s].s.f)}]]){
pq.push({1, eid[{min(a, e[pqi.s].s.f), max(a, e[pqi.s].s.f)}]});
}
}
if(adj[e[pqi.s].s.s].size() == 2){
ll a = *(adj[e[pqi.s].s.s].begin());
ll b = *next(adj[e[pqi.s].s.s].begin());
if(eid.find({min(a, b), max(a, b)}) != eid.end()){
e[eid[{min(a, b), max(a, b)}]].f -= 2;
if(!v[eid[{min(a, b), max(a, b)}]] && e[eid[{min(a, b), max(a, b)}]].f == 0){
pq.push({0, eid[{min(a, b), max(a, b)}]});
}
}
}else if(adj[e[pqi.s].s.s].size() == 1){
ll a = *(adj[e[pqi.s].s.s].begin());
if(!v[eid[{min(a, e[pqi.s].s.s), max(a, e[pqi.s].s.s)}]]){
pq.push({1, eid[{min(a, e[pqi.s].s.s), max(a, e[pqi.s].s.s)}]});
}
}
}
FOR(i, 1, m) if(!v[i] || d[i] % 2 == 1){
cout << 0 << endl;
return 0;
}
//FOR(i, 1, m) cout << d[i] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
4 |
Incorrect |
128 ms |
30288 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
10584 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
10844 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
13 |
Incorrect |
87 ms |
26800 KB |
Output isn't correct |
14 |
Incorrect |
96 ms |
29428 KB |
Output isn't correct |
15 |
Incorrect |
108 ms |
30328 KB |
Output isn't correct |
16 |
Incorrect |
89 ms |
27848 KB |
Output isn't correct |
17 |
Incorrect |
105 ms |
30300 KB |
Output isn't correct |
18 |
Incorrect |
108 ms |
30156 KB |
Output isn't correct |
19 |
Incorrect |
103 ms |
29404 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
10584 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
22 |
Incorrect |
109 ms |
30320 KB |
Output isn't correct |
23 |
Incorrect |
85 ms |
26988 KB |
Output isn't correct |
24 |
Incorrect |
105 ms |
30352 KB |
Output isn't correct |
25 |
Incorrect |
88 ms |
27504 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10584 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
10844 KB |
Output isn't correct |
3 |
Correct |
90 ms |
28772 KB |
Output is correct |
4 |
Correct |
92 ms |
29520 KB |
Output is correct |
5 |
Correct |
97 ms |
29896 KB |
Output is correct |
6 |
Correct |
497 ms |
100040 KB |
Output is correct |
7 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10676 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
13 |
Correct |
2 ms |
10584 KB |
Output is correct |
14 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
17 |
Correct |
2 ms |
10844 KB |
Output is correct |
18 |
Correct |
2 ms |
10876 KB |
Output is correct |
19 |
Correct |
1 ms |
10844 KB |
Output is correct |
20 |
Correct |
1 ms |
10844 KB |
Output is correct |
21 |
Correct |
3 ms |
11096 KB |
Output is correct |
22 |
Incorrect |
2 ms |
10844 KB |
Output isn't correct |
23 |
Incorrect |
70 ms |
26496 KB |
Output isn't correct |
24 |
Incorrect |
94 ms |
29648 KB |
Output isn't correct |
25 |
Correct |
94 ms |
28856 KB |
Output is correct |
26 |
Correct |
100 ms |
29520 KB |
Output is correct |
27 |
Correct |
81 ms |
29268 KB |
Output is correct |
28 |
Correct |
94 ms |
30664 KB |
Output is correct |
29 |
Correct |
366 ms |
84564 KB |
Output is correct |
30 |
Incorrect |
90 ms |
28948 KB |
Output isn't correct |
31 |
Incorrect |
73 ms |
29268 KB |
Output isn't correct |
32 |
Incorrect |
101 ms |
30156 KB |
Output isn't correct |
33 |
Correct |
88 ms |
29744 KB |
Output is correct |
34 |
Correct |
78 ms |
29524 KB |
Output is correct |
35 |
Correct |
90 ms |
29592 KB |
Output is correct |
36 |
Correct |
93 ms |
29908 KB |
Output is correct |
37 |
Correct |
483 ms |
99924 KB |
Output is correct |
38 |
Incorrect |
96 ms |
29524 KB |
Output isn't correct |
39 |
Incorrect |
104 ms |
30156 KB |
Output isn't correct |
40 |
Incorrect |
90 ms |
29648 KB |
Output isn't correct |
41 |
Correct |
75 ms |
29268 KB |
Output is correct |
42 |
Correct |
78 ms |
29264 KB |
Output is correct |
43 |
Correct |
69 ms |
29264 KB |
Output is correct |
44 |
Correct |
95 ms |
29900 KB |
Output is correct |
45 |
Correct |
439 ms |
88848 KB |
Output is correct |
46 |
Incorrect |
94 ms |
29212 KB |
Output isn't correct |
47 |
Incorrect |
91 ms |
29648 KB |
Output isn't correct |
48 |
Incorrect |
78 ms |
29524 KB |
Output isn't correct |
49 |
Correct |
95 ms |
29240 KB |
Output is correct |
50 |
Correct |
84 ms |
29876 KB |
Output is correct |
51 |
Correct |
94 ms |
29644 KB |
Output is correct |
52 |
Correct |
80 ms |
29324 KB |
Output is correct |
53 |
Correct |
463 ms |
90200 KB |
Output is correct |
54 |
Incorrect |
95 ms |
29332 KB |
Output isn't correct |