답안 #228535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228535 2020-05-01T11:16:40 Z Fischer Pipes (BOI13_pipes) C++14
49.2593 / 100
271 ms 18800 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Miguel Mini
 */

#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define set_to(x, v) fill(all(x), v)
#define eb emplace_back
#define lso(x) ((x)&-(x))
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int inf = INT_MAX;
vector<ii> g[maxn];

class pipes {
public:

    void solveOne(istream& in, ostream& out) {
        int n, m;
        in >> n >> m;
        if (m > n) {
            out << 0 << endl;
            return;
        }
        vector<ll> c(n);
        vi deg(n);
        trav(&v, c) in >> v;
        vector<ii> edges;
        re(i, 0, m) {
            int a, b;
            in >> a >> b;
            a -= 1; b -= 1;
            edges.eb(a, b);
            g[a].eb(b, i); deg[a] += 1;
            g[b].eb(a, i); deg[b] += 1;
        }
        vi res(m);
        vector<bool> vis(m);
        queue<int> Q;
        re(i, 0, n) {
            if (sz(g[i]) == 1) {
                Q.push(i);
            }
        }
        while (!Q.empty()) {
            int q = Q.front(); Q.pop();
            for (auto v : g[q]) {
                int id = v.second;
                if (vis[id]) continue;
                vis[id] = 1;
                m -= 1;
                res[id] = 2 * c[q];
                int u = v.first;
                c[u] -= c[q];
                c[q] = 0;
                deg[u] -= 1;
                if (deg[u] == 1) {
                    Q.push(u);
                }
            }
        }
        if (m == 0 and accumulate(all(c), 0ll) == 0) {
            assert(false);
            trav(v, res) out << v << endl;
        } else if (m&1) {
            int x = 0;
            while (deg[x] == 0) x += 1;
            ll sum = 0;
            vector<int> t;
            function<int(int, vi&, ll&)> dfs = [&](int v, vi& t, ll& sum)->int {
                if (deg[v] != 2) return -inf;
                sum = c[v] - sum;
                trav(node, g[v]) {
                    if (!vis[node.second]) {
                        vis[node.second] = 1;
                        t.emplace_back(node.second);
                        if (node.first == x) return 1;
                        return dfs(node.first, t, sum) + 1;
                    }
                }
                return -inf;
            };
            if (dfs(x, t, sum) == m) {
                res[t[0]] = 2 * c[x] - sum;
                sum = res[t[0]];
                re(i, 1, sz(t)) {
                    x ^= edges[t[i-1]].first ^ edges[t[i-1]].second;
                    res[t[i]] = 2 * c[x] - sum;
                    sum = res[t[i]];
                }
                trav(v, res) out << v << endl;
            } else {
                assert(false);
                out << 0 << endl;
            }
        } else {
            assert(false);
            out << 0 << endl;
        }
    }

    void solve(istream& in, ostream& out) {
        int testNumber = 1;
        //in >> testNumber;
        re(tc, 1, testNumber+1) {
            //out << "Case #" << tc << ": ";
            solveOne(in, out);
        }
    }
};


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	pipes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 8 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 10 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 85 ms 18796 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 9 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 9 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 9 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 9 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 9 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 66 ms 16236 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 74 ms 18028 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 83 ms 18800 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 68 ms 16880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 86 ms 18668 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 84 ms 18672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 76 ms 17388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 10 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 78 ms 18668 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 59 ms 16108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 83 ms 18796 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 70 ms 16620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Correct 8 ms 2816 KB Output is correct
3 Runtime error 72 ms 17388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Runtime error 9 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Correct 6 ms 2688 KB Output is correct
9 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Correct 6 ms 2688 KB Output is correct
11 Correct 6 ms 2688 KB Output is correct
12 Correct 6 ms 2688 KB Output is correct
13 Correct 6 ms 2688 KB Output is correct
14 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Correct 8 ms 2816 KB Output is correct
16 Correct 8 ms 2816 KB Output is correct
17 Runtime error 10 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Correct 6 ms 2688 KB Output is correct
19 Correct 6 ms 2688 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 6 ms 2688 KB Output is correct
22 Runtime error 9 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Correct 220 ms 12116 KB Output is correct
24 Correct 257 ms 13420 KB Output is correct
25 Runtime error 72 ms 17388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Correct 6 ms 2688 KB Output is correct
27 Correct 6 ms 2688 KB Output is correct
28 Correct 6 ms 2688 KB Output is correct
29 Correct 6 ms 2688 KB Output is correct
30 Runtime error 77 ms 17132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Correct 271 ms 15820 KB Output is correct
32 Correct 270 ms 11116 KB Output is correct
33 Runtime error 73 ms 17772 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Correct 6 ms 2688 KB Output is correct
35 Correct 6 ms 2688 KB Output is correct
36 Correct 6 ms 2688 KB Output is correct
37 Correct 6 ms 2688 KB Output is correct
38 Correct 260 ms 12784 KB Output is correct
39 Runtime error 82 ms 18416 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 73 ms 17900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 68 ms 17388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Correct 6 ms 2688 KB Output is correct
43 Correct 6 ms 2688 KB Output is correct
44 Correct 6 ms 2688 KB Output is correct
45 Correct 6 ms 2688 KB Output is correct
46 Correct 269 ms 12380 KB Output is correct
47 Runtime error 70 ms 17900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Correct 268 ms 15596 KB Output is correct
49 Runtime error 73 ms 18028 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Correct 6 ms 2688 KB Output is correct
51 Correct 6 ms 2688 KB Output is correct
52 Correct 6 ms 2688 KB Output is correct
53 Correct 6 ms 2688 KB Output is correct
54 Runtime error 77 ms 17388 KB Execution killed with signal 11 (could be triggered by violating memory limits)