Submission #673499

# Submission time Handle Problem Language Result Execution time Memory
673499 2022-12-20T17:39:29 Z Lobo Pipes (BOI13_pipes) C++17
65 / 100
193 ms 51392 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 5e5+10;

int n, m, c[maxn], ans[maxn], gr[maxn];
vector<pair<int,int>> g[maxn], g1[maxn];
int sm = 0;
vector<int> vrt;
int id0 = 0;
void dfs(int u, int ant, int cnt) {
    sm+= cnt*c[u];
    auto V = g1[u][0];
    if(V.fr == ant) V = g1[u][1];
    int v = V.fr;
    int id = V.sc;
    if(v == vrt[0]) return;
    dfs(v,u,cnt*-1);
}

void dfs1(int u, int ant) {
    auto V = g1[u][1];
    if(V.fr == ant) V = g1[u][0];
    int v = V.fr;
    int id = V.sc;
    if(ant == -1) {
        ans[id] = sm;
        c[u]+= sm/2;
    }
    else ans[id] = 2*c[u];
    c[v]-= c[u];
    if(v == vrt[0]) return;
    dfs1(v,u);
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    for(int i = 1; i <= m; i++) {
        int u,v; cin >> u >> v;
        g[u].pb(mp(v,i));
        g[v].pb(mp(u,i));
        gr[u]++;
        gr[v]++;
    }

    if(m > n) {
        cout << 0 << endl;
        return;
    }
    queue<int> q;
    for(int i = 1; i <= n; i++) {
        if(gr[i] == 1) q.push(i);
    }

    while(q.size()) {
        int u = q.front(); q.pop();
        gr[u] = -1;
        for(auto V : g[u]) {
            int v = V.fr;
            int id = V.sc;
            if(gr[v] == -1) continue;
            ans[id] = 2*c[u];
            c[v]-= c[u];
            if(--gr[v] == 1) q.push(v);
        }
    }

    if(m == n) {
        for(int i = 1; i <= n; i++) {
            if(gr[i] != -1) {
                vrt.pb(i);
                for(auto V : g[i]) {
                    if(gr[V.fr] != -1) {
                        g1[i].pb(V);
                    }
                }
            }
        }
        if(vrt.size()%2 == 1) {
            dfs(vrt[0],-1,1);
            dfs1(vrt[0],-1);
        }
        else {

        }

    }

    for(int i = 1; i <= m; i++) {
        cout << ans[i] << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

pipes.cpp: In function 'void dfs(long long int, long long int, long long int)':
pipes.cpp:25:9: warning: unused variable 'id' [-Wunused-variable]
   25 |     int id = V.sc;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23904 KB Output is correct
4 Correct 64 ms 32064 KB Output is correct
5 Correct 12 ms 23720 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23788 KB Output is correct
9 Correct 11 ms 23868 KB Output is correct
10 Correct 12 ms 23892 KB Output is correct
11 Correct 13 ms 23820 KB Output is correct
12 Correct 12 ms 23892 KB Output is correct
13 Correct 52 ms 30360 KB Output is correct
14 Correct 64 ms 31580 KB Output is correct
15 Correct 64 ms 32072 KB Output is correct
16 Correct 57 ms 30816 KB Output is correct
17 Correct 72 ms 32108 KB Output is correct
18 Correct 69 ms 32188 KB Output is correct
19 Correct 67 ms 31692 KB Output is correct
20 Correct 12 ms 23704 KB Output is correct
21 Correct 12 ms 23832 KB Output is correct
22 Correct 65 ms 32076 KB Output is correct
23 Correct 56 ms 30328 KB Output is correct
24 Correct 61 ms 32112 KB Output is correct
25 Correct 61 ms 30744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23840 KB Output isn't correct
2 Incorrect 11 ms 23892 KB Output isn't correct
3 Incorrect 62 ms 33604 KB Output isn't correct
4 Correct 48 ms 30532 KB Output is correct
5 Correct 50 ms 30232 KB Output is correct
6 Correct 187 ms 51392 KB Output is correct
7 Incorrect 12 ms 23764 KB Output isn't correct
8 Incorrect 12 ms 23764 KB Output isn't correct
9 Incorrect 11 ms 23764 KB Output isn't correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 11 ms 23824 KB Output is correct
12 Correct 11 ms 23784 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Incorrect 12 ms 23764 KB Output isn't correct
15 Incorrect 12 ms 23892 KB Output isn't correct
16 Incorrect 12 ms 23892 KB Output isn't correct
17 Incorrect 12 ms 23892 KB Output isn't correct
18 Correct 14 ms 23764 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 12 ms 23892 KB Output is correct
21 Correct 12 ms 23976 KB Output is correct
22 Incorrect 12 ms 23892 KB Output isn't correct
23 Incorrect 71 ms 33184 KB Output isn't correct
24 Incorrect 81 ms 34644 KB Output isn't correct
25 Incorrect 65 ms 33552 KB Output isn't correct
26 Correct 48 ms 30468 KB Output is correct
27 Correct 48 ms 30376 KB Output is correct
28 Correct 49 ms 30800 KB Output is correct
29 Correct 163 ms 46004 KB Output is correct
30 Incorrect 72 ms 33924 KB Output isn't correct
31 Incorrect 89 ms 36388 KB Output isn't correct
32 Incorrect 68 ms 32644 KB Output isn't correct
33 Incorrect 66 ms 34656 KB Output isn't correct
34 Correct 48 ms 30464 KB Output is correct
35 Correct 48 ms 30500 KB Output is correct
36 Correct 48 ms 30540 KB Output is correct
37 Correct 193 ms 51212 KB Output is correct
38 Incorrect 79 ms 34216 KB Output isn't correct
39 Incorrect 69 ms 32148 KB Output isn't correct
40 Incorrect 80 ms 34440 KB Output isn't correct
41 Incorrect 67 ms 36260 KB Output isn't correct
42 Correct 48 ms 30488 KB Output is correct
43 Correct 50 ms 30448 KB Output is correct
44 Correct 47 ms 30236 KB Output is correct
45 Correct 131 ms 48272 KB Output is correct
46 Incorrect 74 ms 33772 KB Output isn't correct
47 Incorrect 73 ms 34436 KB Output isn't correct
48 Incorrect 82 ms 36280 KB Output isn't correct
49 Incorrect 61 ms 31908 KB Output isn't correct
50 Correct 48 ms 30544 KB Output is correct
51 Correct 48 ms 30544 KB Output is correct
52 Correct 52 ms 30444 KB Output is correct
53 Correct 157 ms 47696 KB Output is correct
54 Incorrect 75 ms 33600 KB Output isn't correct