답안 #573635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573635 2022-06-07T03:31:22 Z tengiz05 Graph (BOI20_graph) C++17
58 / 100
106 ms 15584 KB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int inf = 1E9;

void gg() {
    std::cout << "NO\n";
    std::exit(0);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<std::vector<std::pair<int, int>>> adj(n);
    
    for (int i = 0; i < m; i++) {
        int u, v, c;
        std::cin >> u >> v >> c;
        u--;
        v--;
        adj[u].emplace_back(v, c);
        adj[v].emplace_back(u, c);
    }
    
    std::vector<bool> vis(n);
    std::vector<int> col(n), a(n);
    std::vector<double> ans(n);
    
    for (int u = 0; u < n; u++) {
        if (!vis[u]) {
            int res[2] {inf, inf};
            std::vector<int> b;
            
            std::function<void(int)> dfs = [&](int u) {
                vis[u] = true;
                for (auto [v, c] : adj[u]) {
                    if (!vis[v]) {
                        col[v] = col[u] ^ 1;
                        a[v] = c - a[u];
                        dfs(v);
                    } else {
                        if (col[u] != col[v]) {
                            if (a[u] + a[v] != c) {
                                gg();
                            }
                        } else {
                            if (res[col[u]] == inf) {
                                res[col[u]] = c - a[u] - a[v];
                            } else if (res[col[u]] != c - a[u] - a[v]) {
                                gg();
                            }
                        }
                    }
                }
                b.push_back(u);
            };
            
            dfs(u);
            
            if (res[0] != inf) {
                if (res[1] != inf && res[1] != -res[0]) {
                    gg();
                }
                res[1] = -res[0];
            } else if (res[1] != inf) {
                res[0] = -res[1];
            }
            
            if (res[0] != inf) {
                for (int v : b) {
                    ans[v] = a[v] + res[col[v]] / 2.;
                }
            } else {
                std::pair<int, int> best(inf, -1);
                for (int i = -10; i <= 10; i++) {
                    int sum = 0;
                    for (int v : b) {
                        sum += std::abs(a[v] + (col[v] == 0 ? i : -i));
                    }
                    best = std::min(best, std::pair(sum, i));
                }
                
                for (int v : b) {
                    ans[v] = a[v] + (col[v] == 0 ? best.second : -best.second);
                }
            }
        }
    }
    
    std::cout << "YES\n";
    for (int i = 0; i < n; i++) {
        std::cout << ans[i] << " \n"[i == n - 1];
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 0 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 1 ms 212 KB answer = YES
7 Correct 1 ms 320 KB answer = YES
8 Correct 1 ms 212 KB answer = YES
9 Correct 1 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 0 ms 212 KB answer = YES
12 Correct 1 ms 212 KB answer = NO
13 Correct 1 ms 316 KB answer = YES
14 Correct 1 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 212 KB answer = YES
17 Correct 1 ms 212 KB answer = YES
18 Correct 1 ms 212 KB answer = YES
19 Correct 1 ms 212 KB answer = YES
20 Correct 1 ms 212 KB answer = YES
21 Correct 1 ms 212 KB answer = YES
22 Correct 1 ms 212 KB answer = NO
23 Correct 1 ms 212 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 0 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 1 ms 212 KB answer = YES
7 Correct 1 ms 320 KB answer = YES
8 Correct 1 ms 212 KB answer = YES
9 Correct 1 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 0 ms 212 KB answer = YES
12 Correct 1 ms 212 KB answer = NO
13 Correct 1 ms 316 KB answer = YES
14 Correct 1 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 212 KB answer = YES
17 Correct 1 ms 212 KB answer = YES
18 Correct 1 ms 212 KB answer = YES
19 Correct 1 ms 212 KB answer = YES
20 Correct 1 ms 212 KB answer = YES
21 Correct 1 ms 212 KB answer = YES
22 Correct 1 ms 212 KB answer = NO
23 Correct 1 ms 212 KB answer = NO
24 Correct 1 ms 212 KB answer = YES
25 Correct 1 ms 212 KB answer = YES
26 Correct 1 ms 212 KB answer = YES
27 Correct 1 ms 212 KB answer = YES
28 Correct 1 ms 212 KB answer = YES
29 Correct 1 ms 212 KB answer = YES
30 Correct 1 ms 324 KB answer = NO
31 Correct 1 ms 320 KB answer = YES
32 Correct 1 ms 212 KB answer = YES
33 Correct 0 ms 212 KB answer = YES
34 Correct 1 ms 212 KB answer = YES
35 Correct 1 ms 212 KB answer = YES
36 Correct 1 ms 212 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 0 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 1 ms 212 KB answer = YES
7 Correct 1 ms 320 KB answer = YES
8 Correct 1 ms 212 KB answer = YES
9 Correct 1 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 0 ms 212 KB answer = YES
12 Correct 1 ms 212 KB answer = NO
13 Correct 1 ms 316 KB answer = YES
14 Correct 1 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 212 KB answer = YES
17 Correct 1 ms 212 KB answer = YES
18 Correct 1 ms 212 KB answer = YES
19 Correct 1 ms 212 KB answer = YES
20 Correct 1 ms 212 KB answer = YES
21 Correct 1 ms 212 KB answer = YES
22 Correct 1 ms 212 KB answer = NO
23 Correct 1 ms 212 KB answer = NO
24 Correct 1 ms 212 KB answer = YES
25 Correct 1 ms 212 KB answer = YES
26 Correct 1 ms 212 KB answer = YES
27 Correct 1 ms 212 KB answer = YES
28 Correct 1 ms 212 KB answer = YES
29 Correct 1 ms 212 KB answer = YES
30 Correct 1 ms 324 KB answer = NO
31 Correct 1 ms 320 KB answer = YES
32 Correct 1 ms 212 KB answer = YES
33 Correct 0 ms 212 KB answer = YES
34 Correct 1 ms 212 KB answer = YES
35 Correct 1 ms 212 KB answer = YES
36 Correct 1 ms 212 KB answer = YES
37 Correct 1 ms 212 KB answer = YES
38 Correct 1 ms 212 KB answer = YES
39 Correct 1 ms 324 KB answer = YES
40 Correct 2 ms 340 KB answer = YES
41 Correct 1 ms 340 KB answer = NO
42 Correct 2 ms 340 KB answer = YES
43 Correct 1 ms 340 KB answer = YES
44 Correct 2 ms 340 KB answer = YES
45 Correct 1 ms 328 KB answer = YES
46 Correct 1 ms 324 KB answer = YES
47 Correct 1 ms 324 KB answer = YES
48 Correct 2 ms 340 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 0 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 1 ms 212 KB answer = YES
7 Correct 1 ms 320 KB answer = YES
8 Correct 1 ms 212 KB answer = YES
9 Correct 1 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 0 ms 212 KB answer = YES
12 Correct 1 ms 212 KB answer = NO
13 Correct 1 ms 316 KB answer = YES
14 Correct 1 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 212 KB answer = YES
17 Correct 1 ms 212 KB answer = YES
18 Correct 1 ms 212 KB answer = YES
19 Correct 1 ms 212 KB answer = YES
20 Correct 1 ms 212 KB answer = YES
21 Correct 1 ms 212 KB answer = YES
22 Correct 1 ms 212 KB answer = NO
23 Correct 1 ms 212 KB answer = NO
24 Correct 1 ms 212 KB answer = YES
25 Correct 1 ms 212 KB answer = YES
26 Correct 1 ms 212 KB answer = YES
27 Correct 1 ms 212 KB answer = YES
28 Correct 1 ms 212 KB answer = YES
29 Correct 1 ms 212 KB answer = YES
30 Correct 1 ms 324 KB answer = NO
31 Correct 1 ms 320 KB answer = YES
32 Correct 1 ms 212 KB answer = YES
33 Correct 0 ms 212 KB answer = YES
34 Correct 1 ms 212 KB answer = YES
35 Correct 1 ms 212 KB answer = YES
36 Correct 1 ms 212 KB answer = YES
37 Correct 1 ms 212 KB answer = YES
38 Correct 1 ms 212 KB answer = YES
39 Correct 1 ms 324 KB answer = YES
40 Correct 2 ms 340 KB answer = YES
41 Correct 1 ms 340 KB answer = NO
42 Correct 2 ms 340 KB answer = YES
43 Correct 1 ms 340 KB answer = YES
44 Correct 2 ms 340 KB answer = YES
45 Correct 1 ms 328 KB answer = YES
46 Correct 1 ms 324 KB answer = YES
47 Correct 1 ms 324 KB answer = YES
48 Correct 2 ms 340 KB answer = YES
49 Correct 8 ms 1344 KB answer = YES
50 Correct 11 ms 1620 KB answer = YES
51 Correct 11 ms 1620 KB answer = YES
52 Correct 5 ms 1108 KB answer = NO
53 Correct 1 ms 340 KB answer = YES
54 Correct 2 ms 556 KB answer = YES
55 Correct 4 ms 720 KB answer = YES
56 Correct 12 ms 1228 KB answer = YES
57 Correct 12 ms 1236 KB answer = YES
58 Correct 9 ms 1192 KB answer = YES
59 Correct 7 ms 1108 KB answer = YES
60 Correct 8 ms 1236 KB answer = YES
61 Correct 4 ms 724 KB answer = YES
62 Correct 49 ms 7564 KB answer = NO
63 Correct 60 ms 8020 KB answer = YES
64 Correct 68 ms 8032 KB answer = NO
65 Correct 83 ms 8136 KB answer = YES
66 Correct 3 ms 468 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 0 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 1 ms 212 KB answer = YES
7 Correct 1 ms 320 KB answer = YES
8 Correct 1 ms 212 KB answer = YES
9 Correct 1 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 0 ms 212 KB answer = YES
12 Correct 1 ms 212 KB answer = NO
13 Correct 1 ms 316 KB answer = YES
14 Correct 1 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 212 KB answer = YES
17 Correct 1 ms 212 KB answer = YES
18 Correct 1 ms 212 KB answer = YES
19 Correct 1 ms 212 KB answer = YES
20 Correct 1 ms 212 KB answer = YES
21 Correct 1 ms 212 KB answer = YES
22 Correct 1 ms 212 KB answer = NO
23 Correct 1 ms 212 KB answer = NO
24 Correct 1 ms 212 KB answer = YES
25 Correct 1 ms 212 KB answer = YES
26 Correct 1 ms 212 KB answer = YES
27 Correct 1 ms 212 KB answer = YES
28 Correct 1 ms 212 KB answer = YES
29 Correct 1 ms 212 KB answer = YES
30 Correct 1 ms 324 KB answer = NO
31 Correct 1 ms 320 KB answer = YES
32 Correct 1 ms 212 KB answer = YES
33 Correct 0 ms 212 KB answer = YES
34 Correct 1 ms 212 KB answer = YES
35 Correct 1 ms 212 KB answer = YES
36 Correct 1 ms 212 KB answer = YES
37 Correct 1 ms 212 KB answer = YES
38 Correct 1 ms 212 KB answer = YES
39 Correct 1 ms 324 KB answer = YES
40 Correct 2 ms 340 KB answer = YES
41 Correct 1 ms 340 KB answer = NO
42 Correct 2 ms 340 KB answer = YES
43 Correct 1 ms 340 KB answer = YES
44 Correct 2 ms 340 KB answer = YES
45 Correct 1 ms 328 KB answer = YES
46 Correct 1 ms 324 KB answer = YES
47 Correct 1 ms 324 KB answer = YES
48 Correct 2 ms 340 KB answer = YES
49 Correct 8 ms 1344 KB answer = YES
50 Correct 11 ms 1620 KB answer = YES
51 Correct 11 ms 1620 KB answer = YES
52 Correct 5 ms 1108 KB answer = NO
53 Correct 1 ms 340 KB answer = YES
54 Correct 2 ms 556 KB answer = YES
55 Correct 4 ms 720 KB answer = YES
56 Correct 12 ms 1228 KB answer = YES
57 Correct 12 ms 1236 KB answer = YES
58 Correct 9 ms 1192 KB answer = YES
59 Correct 7 ms 1108 KB answer = YES
60 Correct 8 ms 1236 KB answer = YES
61 Correct 4 ms 724 KB answer = YES
62 Correct 49 ms 7564 KB answer = NO
63 Correct 60 ms 8020 KB answer = YES
64 Correct 68 ms 8032 KB answer = NO
65 Correct 83 ms 8136 KB answer = YES
66 Correct 3 ms 468 KB answer = YES
67 Incorrect 106 ms 15584 KB participant answer is larger than the answer of jury
68 Halted 0 ms 0 KB -