Submission #742018

# Submission time Handle Problem Language Result Execution time Memory
742018 2023-05-15T11:40:47 Z irmuun Pipes (BOI13_pipes) C++17
74.0741 / 100
254 ms 21664 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,m;
    cin>>n>>m;
    if(m!=n-1){
        cout<<0;
        return 0;
    }
    map<pair<ll,ll>,ll>mp;
    set<ll>s[n+5];
    ll c[n+5],p[n+5];
    fill(p,p+n+1,0);
    for(ll i=1;i<=n;i++){
        cin>>c[i];
    }
    vector<pair<ll,ll>>edge;
    for(ll i=1;i<=m;i++){
        ll u,v;
        cin>>u>>v;
        edge.pb({u,v});
        s[u].insert(v);
        s[v].insert(u);
        p[u]++;
        p[v]++;
    }
    queue<ll>q;
    for(ll i=1;i<=n;i++){
        if(p[i]==1){
            q.push(i);
        }
    }
    for(ll i=1;i<n;i++){
        ll x=q.front();
        q.pop();
        if(p[x]==0){
            continue;
        }
        ll y=*s[x].begin();
        mp[{x,y}]=2*c[x];
        c[y]-=c[x];
        p[y]--;
        p[x]--;
        s[x].erase(y);
        s[y].erase(x);
        if(p[y]==1){
            q.push(y);
        }
    }
    if(c[q.front()]!=0){
        cout<<0;
        return 0;
    }
    for(auto [u,v]:edge){
        cout<<mp[{u,v}]+mp[{v,u}]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 190 ms 21492 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 162 ms 17196 KB Output is correct
14 Correct 190 ms 20464 KB Output is correct
15 Correct 254 ms 21664 KB Output is correct
16 Correct 156 ms 18512 KB Output is correct
17 Correct 203 ms 21600 KB Output is correct
18 Correct 193 ms 21660 KB Output is correct
19 Correct 203 ms 21420 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 215 ms 21560 KB Output is correct
23 Correct 138 ms 17180 KB Output is correct
24 Correct 197 ms 21660 KB Output is correct
25 Correct 164 ms 17996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Incorrect 0 ms 212 KB Output isn't correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Incorrect 0 ms 212 KB Output isn't correct
23 Incorrect 0 ms 212 KB Output isn't correct
24 Incorrect 0 ms 212 KB Output isn't correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Incorrect 0 ms 212 KB Output isn't correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Incorrect 0 ms 212 KB Output isn't correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Incorrect 0 ms 212 KB Output isn't correct
39 Incorrect 0 ms 212 KB Output isn't correct
40 Incorrect 0 ms 212 KB Output isn't correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Incorrect 0 ms 212 KB Output isn't correct
47 Incorrect 0 ms 212 KB Output isn't correct
48 Incorrect 0 ms 212 KB Output isn't correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Incorrect 0 ms 212 KB Output isn't correct