Submission #677754

# Submission time Handle Problem Language Result Execution time Memory
677754 2023-01-04T10:00:35 Z dooompy Pipes (BOI13_pipes) C++17
42.7778 / 100
161 ms 24000 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

ll v[100005];
int deg[100005];

vector<pair<int, int>> adj[100005];
ll calc[500005];

bool seen[100005];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> v[i];
    for (int i = 1; i <= m; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back({b, i});
        adj[b].push_back({a, i});
        deg[a]++; deg[b]++;
    }

    queue<int> q;

    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        // deg 1
        auto cur = q.front(); q.pop();
        seen[cur] = true;
        deg[cur] == 0;

        auto to = adj[cur][0];
        if (seen[to.first]) continue;
        ll weight = v[cur];

        v[to.first] -= weight;
        calc[to.second] = weight;

        if (--deg[to.first] == 1) {
            q.push(to.first);
        }
    }

    if (m == n - 1) {
        for (int i = 1; i <= m; i++) {
            cout << calc[i] * 2 << "\n";
        }
        return 0;
    }

    if (m > n || m % 2 == 0) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = i; i <= n; i++) {
        assert(deg[i] == 2);
    }
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:66:18: warning: statement has no effect [-Wunused-value]
   66 |         deg[cur] == 0;
      |         ~~~~~~~~~^~~~
pipes.cpp:92:14: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   92 |     for (int i = i; i <= n; i++) {
      |              ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Incorrect 48 ms 10540 KB Output isn't correct
5 Incorrect 2 ms 2644 KB Output isn't correct
6 Incorrect 2 ms 2644 KB Output isn't correct
7 Incorrect 2 ms 2684 KB Output isn't correct
8 Incorrect 2 ms 2688 KB Output isn't correct
9 Incorrect 2 ms 2644 KB Output isn't correct
10 Incorrect 2 ms 2644 KB Output isn't correct
11 Incorrect 2 ms 2696 KB Output isn't correct
12 Incorrect 2 ms 2644 KB Output isn't correct
13 Incorrect 51 ms 9032 KB Output isn't correct
14 Incorrect 46 ms 10068 KB Output isn't correct
15 Incorrect 49 ms 10552 KB Output isn't correct
16 Incorrect 39 ms 9292 KB Output isn't correct
17 Incorrect 47 ms 10444 KB Output isn't correct
18 Incorrect 49 ms 10592 KB Output isn't correct
19 Incorrect 45 ms 9724 KB Output isn't correct
20 Incorrect 2 ms 2644 KB Output isn't correct
21 Incorrect 2 ms 2648 KB Output isn't correct
22 Incorrect 49 ms 10508 KB Output isn't correct
23 Incorrect 38 ms 8908 KB Output isn't correct
24 Incorrect 53 ms 10556 KB Output isn't correct
25 Incorrect 38 ms 9196 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Incorrect 2 ms 2696 KB Output isn't correct
3 Correct 40 ms 9464 KB Output is correct
4 Correct 43 ms 9576 KB Output is correct
5 Correct 39 ms 9816 KB Output is correct
6 Correct 161 ms 24000 KB Output is correct
7 Incorrect 1 ms 2644 KB Output isn't correct
8 Runtime error 4 ms 5204 KB Execution killed with signal 6
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2680 KB Output is correct
14 Incorrect 1 ms 2644 KB Output isn't correct
15 Incorrect 2 ms 2692 KB Output isn't correct
16 Runtime error 4 ms 5332 KB Execution killed with signal 6
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Incorrect 2 ms 2688 KB Output isn't correct
23 Runtime error 35 ms 15540 KB Execution killed with signal 6
24 Incorrect 38 ms 9728 KB Output isn't correct
25 Correct 38 ms 9468 KB Output is correct
26 Correct 39 ms 9584 KB Output is correct
27 Correct 42 ms 9380 KB Output is correct
28 Correct 41 ms 10060 KB Output is correct
29 Correct 125 ms 20728 KB Output is correct
30 Incorrect 40 ms 9276 KB Output isn't correct
31 Runtime error 42 ms 17480 KB Execution killed with signal 6
32 Runtime error 48 ms 18712 KB Execution killed with signal 6
33 Correct 37 ms 9676 KB Output is correct
34 Correct 40 ms 9520 KB Output is correct
35 Correct 40 ms 9592 KB Output is correct
36 Correct 42 ms 9924 KB Output is correct
37 Correct 151 ms 23884 KB Output is correct
38 Incorrect 38 ms 9588 KB Output isn't correct
39 Runtime error 50 ms 18684 KB Execution killed with signal 6
40 Incorrect 40 ms 9756 KB Output isn't correct
41 Runtime error 41 ms 17528 KB Execution killed with signal 6
42 Correct 37 ms 9360 KB Output is correct
43 Correct 38 ms 9344 KB Output is correct
44 Correct 40 ms 9876 KB Output is correct
45 Correct 110 ms 20816 KB Output is correct
46 Incorrect 36 ms 9280 KB Output isn't correct
47 Incorrect 39 ms 9744 KB Output isn't correct
48 Runtime error 45 ms 17548 KB Execution killed with signal 6
49 Correct 39 ms 9672 KB Output is correct
50 Correct 44 ms 9740 KB Output is correct
51 Correct 39 ms 9804 KB Output is correct
52 Correct 37 ms 9464 KB Output is correct
53 Correct 129 ms 20992 KB Output is correct
54 Incorrect 37 ms 9484 KB Output isn't correct