Submission #395346

# Submission time Handle Problem Language Result Execution time Memory
395346 2021-04-28T08:48:19 Z KoD Graph (BOI20_graph) C++17
100 / 100
324 ms 20080 KB
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

int main() {
    int N, M;
    std::cin >> N >> M;
    Vec<int> A(M), B(M), C(M);
    Vec<Vec<std::pair<int, int>>> graph(N);
    for (int i = 0; i < M; ++i) {
        std::cin >> A[i] >> B[i] >> C[i];
        A[i] -= 1;
        B[i] -= 1;
        C[i] *= 2;
        graph[A[i]].emplace_back(B[i], C[i]);
        graph[B[i]].emplace_back(A[i], C[i]);
    }
    Vec<bool> done(N);
    Vec<std::pair<int, int>> coeff(N);
    Vec<int> val(N);
    Vec<int> visited;
    auto dfs = [&](auto&& dfs, const int u) -> void {
        done[u] = true;
        visited.push_back(u);
        for (const auto [v, c]: graph[u]) {
            if (!done[v]) {
                coeff[v].first = -coeff[u].first;
                coeff[v].second = c - coeff[u].second;
                dfs(dfs, v);
            }
        }
    };
    for (int src = 0; src < N; ++src) {
        if (!done[src]) {
            coeff[src].first = 1;
            coeff[src].second = 0;
            dfs(dfs, src);
            bool sole = false;
            Vec<int> pts;
            for (const auto u: visited) {
                pts.push_back(-coeff[u].first * coeff[u].second);
                for (const auto [v, c]: graph[u]) {
                    if (coeff[u].first == coeff[v].first) {
                        val[src] = (c - coeff[u].second - coeff[v].second) / (coeff[u].first + coeff[v].first);
                        sole = true;
                    }
                }
            }
            if (!sole) {
                std::sort(pts.begin(), pts.end());
                val[src] = pts[pts.size() / 2];
            }
            for (const auto u: visited) {
                if (u != src) {
                    val[u] = val[src] * coeff[u].first + coeff[u].second;
                }
            }
            visited.clear();
        }
    }
    for (int i = 0; i < M; ++i) {
        if (val[A[i]] + val[B[i]] != C[i]) {
            std::cout << "NO\n";
            return 0;
        }
    }
    std::cout << "YES\n";
    for (int i = 0; i < N; ++i) {
        std::cout << (double) val[i] / 2 << " \n"[i + 1 == N];
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB answer = YES
2 Correct 1 ms 204 KB answer = YES
3 Correct 1 ms 204 KB answer = YES
4 Correct 1 ms 204 KB answer = NO
5 Correct 1 ms 204 KB answer = YES
6 Correct 1 ms 204 KB answer = YES
7 Correct 1 ms 204 KB answer = YES
8 Correct 1 ms 204 KB answer = YES
9 Correct 1 ms 204 KB answer = NO
10 Correct 1 ms 204 KB answer = YES
11 Correct 1 ms 204 KB answer = YES
12 Correct 1 ms 204 KB answer = NO
13 Correct 1 ms 204 KB answer = YES
14 Correct 1 ms 204 KB answer = YES
15 Correct 1 ms 204 KB answer = YES
16 Correct 1 ms 204 KB answer = YES
17 Correct 1 ms 204 KB answer = YES
18 Correct 1 ms 204 KB answer = YES
19 Correct 1 ms 204 KB answer = YES
20 Correct 1 ms 204 KB answer = YES
21 Correct 1 ms 204 KB answer = YES
22 Correct 1 ms 204 KB answer = NO
23 Correct 1 ms 204 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB answer = YES
2 Correct 1 ms 204 KB answer = YES
3 Correct 1 ms 204 KB answer = YES
4 Correct 1 ms 204 KB answer = NO
5 Correct 1 ms 204 KB answer = YES
6 Correct 1 ms 204 KB answer = YES
7 Correct 1 ms 204 KB answer = YES
8 Correct 1 ms 204 KB answer = YES
9 Correct 1 ms 204 KB answer = NO
10 Correct 1 ms 204 KB answer = YES
11 Correct 1 ms 204 KB answer = YES
12 Correct 1 ms 204 KB answer = NO
13 Correct 1 ms 204 KB answer = YES
14 Correct 1 ms 204 KB answer = YES
15 Correct 1 ms 204 KB answer = YES
16 Correct 1 ms 204 KB answer = YES
17 Correct 1 ms 204 KB answer = YES
18 Correct 1 ms 204 KB answer = YES
19 Correct 1 ms 204 KB answer = YES
20 Correct 1 ms 204 KB answer = YES
21 Correct 1 ms 204 KB answer = YES
22 Correct 1 ms 204 KB answer = NO
23 Correct 1 ms 204 KB answer = NO
24 Correct 1 ms 204 KB answer = YES
25 Correct 1 ms 204 KB answer = YES
26 Correct 1 ms 204 KB answer = YES
27 Correct 1 ms 204 KB answer = YES
28 Correct 1 ms 204 KB answer = YES
29 Correct 1 ms 204 KB answer = YES
30 Correct 1 ms 204 KB answer = NO
31 Correct 1 ms 204 KB answer = YES
32 Correct 1 ms 204 KB answer = YES
33 Correct 1 ms 204 KB answer = YES
34 Correct 1 ms 204 KB answer = YES
35 Correct 1 ms 204 KB answer = YES
36 Correct 1 ms 204 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB answer = YES
2 Correct 1 ms 204 KB answer = YES
3 Correct 1 ms 204 KB answer = YES
4 Correct 1 ms 204 KB answer = NO
5 Correct 1 ms 204 KB answer = YES
6 Correct 1 ms 204 KB answer = YES
7 Correct 1 ms 204 KB answer = YES
8 Correct 1 ms 204 KB answer = YES
9 Correct 1 ms 204 KB answer = NO
10 Correct 1 ms 204 KB answer = YES
11 Correct 1 ms 204 KB answer = YES
12 Correct 1 ms 204 KB answer = NO
13 Correct 1 ms 204 KB answer = YES
14 Correct 1 ms 204 KB answer = YES
15 Correct 1 ms 204 KB answer = YES
16 Correct 1 ms 204 KB answer = YES
17 Correct 1 ms 204 KB answer = YES
18 Correct 1 ms 204 KB answer = YES
19 Correct 1 ms 204 KB answer = YES
20 Correct 1 ms 204 KB answer = YES
21 Correct 1 ms 204 KB answer = YES
22 Correct 1 ms 204 KB answer = NO
23 Correct 1 ms 204 KB answer = NO
24 Correct 1 ms 204 KB answer = YES
25 Correct 1 ms 204 KB answer = YES
26 Correct 1 ms 204 KB answer = YES
27 Correct 1 ms 204 KB answer = YES
28 Correct 1 ms 204 KB answer = YES
29 Correct 1 ms 204 KB answer = YES
30 Correct 1 ms 204 KB answer = NO
31 Correct 1 ms 204 KB answer = YES
32 Correct 1 ms 204 KB answer = YES
33 Correct 1 ms 204 KB answer = YES
34 Correct 1 ms 204 KB answer = YES
35 Correct 1 ms 204 KB answer = YES
36 Correct 1 ms 204 KB answer = YES
37 Correct 1 ms 204 KB answer = YES
38 Correct 1 ms 204 KB answer = YES
39 Correct 1 ms 332 KB answer = YES
40 Correct 2 ms 344 KB answer = YES
41 Correct 2 ms 332 KB answer = NO
42 Correct 2 ms 332 KB answer = YES
43 Correct 2 ms 332 KB answer = YES
44 Correct 2 ms 332 KB answer = YES
45 Correct 2 ms 332 KB answer = YES
46 Correct 1 ms 332 KB answer = YES
47 Correct 3 ms 332 KB answer = YES
48 Correct 2 ms 332 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB answer = YES
2 Correct 1 ms 204 KB answer = YES
3 Correct 1 ms 204 KB answer = YES
4 Correct 1 ms 204 KB answer = NO
5 Correct 1 ms 204 KB answer = YES
6 Correct 1 ms 204 KB answer = YES
7 Correct 1 ms 204 KB answer = YES
8 Correct 1 ms 204 KB answer = YES
9 Correct 1 ms 204 KB answer = NO
10 Correct 1 ms 204 KB answer = YES
11 Correct 1 ms 204 KB answer = YES
12 Correct 1 ms 204 KB answer = NO
13 Correct 1 ms 204 KB answer = YES
14 Correct 1 ms 204 KB answer = YES
15 Correct 1 ms 204 KB answer = YES
16 Correct 1 ms 204 KB answer = YES
17 Correct 1 ms 204 KB answer = YES
18 Correct 1 ms 204 KB answer = YES
19 Correct 1 ms 204 KB answer = YES
20 Correct 1 ms 204 KB answer = YES
21 Correct 1 ms 204 KB answer = YES
22 Correct 1 ms 204 KB answer = NO
23 Correct 1 ms 204 KB answer = NO
24 Correct 1 ms 204 KB answer = YES
25 Correct 1 ms 204 KB answer = YES
26 Correct 1 ms 204 KB answer = YES
27 Correct 1 ms 204 KB answer = YES
28 Correct 1 ms 204 KB answer = YES
29 Correct 1 ms 204 KB answer = YES
30 Correct 1 ms 204 KB answer = NO
31 Correct 1 ms 204 KB answer = YES
32 Correct 1 ms 204 KB answer = YES
33 Correct 1 ms 204 KB answer = YES
34 Correct 1 ms 204 KB answer = YES
35 Correct 1 ms 204 KB answer = YES
36 Correct 1 ms 204 KB answer = YES
37 Correct 1 ms 204 KB answer = YES
38 Correct 1 ms 204 KB answer = YES
39 Correct 1 ms 332 KB answer = YES
40 Correct 2 ms 344 KB answer = YES
41 Correct 2 ms 332 KB answer = NO
42 Correct 2 ms 332 KB answer = YES
43 Correct 2 ms 332 KB answer = YES
44 Correct 2 ms 332 KB answer = YES
45 Correct 2 ms 332 KB answer = YES
46 Correct 1 ms 332 KB answer = YES
47 Correct 3 ms 332 KB answer = YES
48 Correct 2 ms 332 KB answer = YES
49 Correct 19 ms 1432 KB answer = YES
50 Correct 18 ms 1760 KB answer = YES
51 Correct 15 ms 1612 KB answer = YES
52 Correct 11 ms 1612 KB answer = NO
53 Correct 2 ms 332 KB answer = YES
54 Correct 6 ms 460 KB answer = YES
55 Correct 8 ms 844 KB answer = YES
56 Correct 15 ms 1320 KB answer = YES
57 Correct 14 ms 1180 KB answer = YES
58 Correct 13 ms 1228 KB answer = YES
59 Correct 17 ms 1228 KB answer = YES
60 Correct 17 ms 1272 KB answer = YES
61 Correct 7 ms 752 KB answer = YES
62 Correct 193 ms 8292 KB answer = NO
63 Correct 186 ms 8208 KB answer = YES
64 Correct 178 ms 8260 KB answer = NO
65 Correct 188 ms 8340 KB answer = YES
66 Correct 3 ms 460 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB answer = YES
2 Correct 1 ms 204 KB answer = YES
3 Correct 1 ms 204 KB answer = YES
4 Correct 1 ms 204 KB answer = NO
5 Correct 1 ms 204 KB answer = YES
6 Correct 1 ms 204 KB answer = YES
7 Correct 1 ms 204 KB answer = YES
8 Correct 1 ms 204 KB answer = YES
9 Correct 1 ms 204 KB answer = NO
10 Correct 1 ms 204 KB answer = YES
11 Correct 1 ms 204 KB answer = YES
12 Correct 1 ms 204 KB answer = NO
13 Correct 1 ms 204 KB answer = YES
14 Correct 1 ms 204 KB answer = YES
15 Correct 1 ms 204 KB answer = YES
16 Correct 1 ms 204 KB answer = YES
17 Correct 1 ms 204 KB answer = YES
18 Correct 1 ms 204 KB answer = YES
19 Correct 1 ms 204 KB answer = YES
20 Correct 1 ms 204 KB answer = YES
21 Correct 1 ms 204 KB answer = YES
22 Correct 1 ms 204 KB answer = NO
23 Correct 1 ms 204 KB answer = NO
24 Correct 1 ms 204 KB answer = YES
25 Correct 1 ms 204 KB answer = YES
26 Correct 1 ms 204 KB answer = YES
27 Correct 1 ms 204 KB answer = YES
28 Correct 1 ms 204 KB answer = YES
29 Correct 1 ms 204 KB answer = YES
30 Correct 1 ms 204 KB answer = NO
31 Correct 1 ms 204 KB answer = YES
32 Correct 1 ms 204 KB answer = YES
33 Correct 1 ms 204 KB answer = YES
34 Correct 1 ms 204 KB answer = YES
35 Correct 1 ms 204 KB answer = YES
36 Correct 1 ms 204 KB answer = YES
37 Correct 1 ms 204 KB answer = YES
38 Correct 1 ms 204 KB answer = YES
39 Correct 1 ms 332 KB answer = YES
40 Correct 2 ms 344 KB answer = YES
41 Correct 2 ms 332 KB answer = NO
42 Correct 2 ms 332 KB answer = YES
43 Correct 2 ms 332 KB answer = YES
44 Correct 2 ms 332 KB answer = YES
45 Correct 2 ms 332 KB answer = YES
46 Correct 1 ms 332 KB answer = YES
47 Correct 3 ms 332 KB answer = YES
48 Correct 2 ms 332 KB answer = YES
49 Correct 19 ms 1432 KB answer = YES
50 Correct 18 ms 1760 KB answer = YES
51 Correct 15 ms 1612 KB answer = YES
52 Correct 11 ms 1612 KB answer = NO
53 Correct 2 ms 332 KB answer = YES
54 Correct 6 ms 460 KB answer = YES
55 Correct 8 ms 844 KB answer = YES
56 Correct 15 ms 1320 KB answer = YES
57 Correct 14 ms 1180 KB answer = YES
58 Correct 13 ms 1228 KB answer = YES
59 Correct 17 ms 1228 KB answer = YES
60 Correct 17 ms 1272 KB answer = YES
61 Correct 7 ms 752 KB answer = YES
62 Correct 193 ms 8292 KB answer = NO
63 Correct 186 ms 8208 KB answer = YES
64 Correct 178 ms 8260 KB answer = NO
65 Correct 188 ms 8340 KB answer = YES
66 Correct 3 ms 460 KB answer = YES
67 Correct 149 ms 15652 KB answer = YES
68 Correct 157 ms 15624 KB answer = YES
69 Correct 147 ms 15684 KB answer = YES
70 Correct 262 ms 20080 KB answer = YES
71 Correct 169 ms 15812 KB answer = YES
72 Correct 194 ms 10232 KB answer = YES
73 Correct 184 ms 10272 KB answer = YES
74 Correct 122 ms 9240 KB answer = YES
75 Correct 77 ms 9456 KB answer = NO
76 Correct 18 ms 1632 KB answer = YES
77 Correct 41 ms 2944 KB answer = YES
78 Correct 67 ms 4616 KB answer = YES
79 Correct 152 ms 8780 KB answer = YES
80 Correct 105 ms 9436 KB answer = YES
81 Correct 113 ms 12744 KB answer = NO
82 Correct 185 ms 15188 KB answer = YES
83 Correct 200 ms 15744 KB answer = YES
84 Correct 194 ms 15864 KB answer = YES
85 Correct 159 ms 15688 KB answer = YES
86 Correct 157 ms 15840 KB answer = YES
87 Correct 148 ms 10940 KB answer = NO
88 Correct 188 ms 11708 KB answer = YES
89 Correct 166 ms 8748 KB answer = YES
90 Correct 158 ms 8652 KB answer = YES
91 Correct 180 ms 8576 KB answer = YES
92 Correct 102 ms 5244 KB answer = YES
93 Correct 75 ms 5316 KB answer = YES
94 Correct 131 ms 15796 KB answer = NO
95 Correct 126 ms 8324 KB answer = NO
96 Correct 324 ms 17464 KB answer = YES
97 Correct 104 ms 15688 KB answer = NO