Submission #283170

# Submission time Handle Problem Language Result Execution time Memory
283170 2020-08-25T10:51:13 Z egekabas Pipes (BOI13_pipes) C++14
74.0741 / 100
112 ms 18680 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
ll n, m;
ll vert[100009];
ll deg[100009];
vector<pll> g[100009];
ll vis[100009];
ll ans[500009];
pll val[500009];
void dfs1(ll v){
    vis[v] = 1;
    for(auto u : g[v]){
        if(vis[u.ff])
            continue;
        ans[u.ss] = vert[v];
        vert[v] -= ans[u.ss];
        vert[u.ff] -= ans[u.ss];
        deg[v]--;
        deg[u.ff]--;
        if(deg[u.ff] <= 1)
            dfs1(u.ff);
    }
}
void dfs2(ll v, pll curval){
    vis[v] = 1;
    for(auto u : g[v]){
        if(val[u.ss].ff == 0)
            val[u.ss] = curval;
        if(vis[u.ff])
            continue;
        dfs2(u.ff, {-curval.ff, vert[u.ff]-curval.ss});
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> m;
    if(m > n){
        cout << "0\n";
        return 0;
    }
    for(ll i = 1; i <= n; ++i)
        cin >> vert[i];
    for(ll i = 0; i < m; ++i){
        ll x, y;
        cin >> x >> y;
        deg[x]++;
        deg[y]++;
        g[x].pb({y, i});
        g[y].pb({x, i});
    }
    for(ll i = 1; i <= n; ++i)
        if(vis[i] == 0 && deg[i] == 1)
            dfs1(i);
    ll var;
    for(ll i = 1; i <= n; ++i)
        if(vis[i] == 0){
            vector<ll> ed;
            for(auto u : g[i])
                if(vis[u.ff] == 0)
                    ed.pb(u.ss);
            dfs2(i, {1, 0});
            pii curval = {val[ed[0]].ff+val[ed[1]].ff, val[ed[0]].ss+val[ed[1]].ss};
            if(curval.ff == 0){
                cout << "0\n";
                return 0;
            }
            var = (vert[i]-curval.ss)/curval.ff;
        }
    for(int i = 0; i < m; ++i){
        if(val[i].ff != 0)
            ans[i] = var*val[i].ff+val[i].ss;
        cout << 2*ans[i] << '\n';
    }
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:88:25: warning: 'var' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             ans[i] = var*val[i].ff+val[i].ss;
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2816 KB Output is correct
4 Correct 87 ms 12920 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 3 ms 2816 KB Output is correct
13 Correct 67 ms 10872 KB Output is correct
14 Correct 80 ms 12408 KB Output is correct
15 Correct 84 ms 13048 KB Output is correct
16 Correct 68 ms 11384 KB Output is correct
17 Correct 85 ms 12920 KB Output is correct
18 Correct 89 ms 13048 KB Output is correct
19 Correct 95 ms 14072 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2816 KB Output is correct
22 Correct 96 ms 13048 KB Output is correct
23 Correct 75 ms 10936 KB Output is correct
24 Correct 84 ms 13048 KB Output is correct
25 Correct 73 ms 11384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Incorrect 2 ms 2944 KB Output isn't correct
3 Correct 81 ms 15568 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Incorrect 2 ms 2688 KB Output isn't correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Incorrect 2 ms 2688 KB Output isn't correct
15 Incorrect 3 ms 2944 KB Output isn't correct
16 Incorrect 3 ms 2816 KB Output isn't correct
17 Correct 2 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Incorrect 3 ms 2816 KB Output isn't correct
23 Incorrect 73 ms 14840 KB Output isn't correct
24 Incorrect 88 ms 17144 KB Output isn't correct
25 Correct 74 ms 15608 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Incorrect 90 ms 16504 KB Output isn't correct
31 Incorrect 92 ms 18680 KB Output isn't correct
32 Incorrect 101 ms 15352 KB Output isn't correct
33 Correct 78 ms 16760 KB Output is correct
34 Correct 2 ms 2816 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 3 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Incorrect 92 ms 16888 KB Output isn't correct
39 Incorrect 87 ms 14968 KB Output isn't correct
40 Incorrect 93 ms 16888 KB Output isn't correct
41 Correct 93 ms 18296 KB Output is correct
42 Correct 2 ms 2688 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Incorrect 89 ms 16504 KB Output isn't correct
47 Incorrect 112 ms 17016 KB Output isn't correct
48 Incorrect 92 ms 18552 KB Output isn't correct
49 Correct 71 ms 14076 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 2 ms 2688 KB Output is correct
52 Correct 2 ms 2688 KB Output is correct
53 Correct 2 ms 2688 KB Output is correct
54 Incorrect 96 ms 16248 KB Output isn't correct