Submission #573628

# Submission time Handle Problem Language Result Execution time Memory
573628 2022-06-07T03:18:02 Z tengiz05 Graph (BOI20_graph) C++17
5 / 100
1 ms 324 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 = -2; i <= 2; 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 320 KB answer = YES
4 Correct 1 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 0 ms 320 KB answer = YES
7 Correct 0 ms 212 KB answer = YES
8 Correct 0 ms 212 KB answer = YES
9 Correct 0 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 1 ms 316 KB answer = YES
12 Correct 0 ms 212 KB answer = NO
13 Correct 1 ms 212 KB answer = YES
14 Correct 0 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 320 KB answer = YES
17 Correct 0 ms 212 KB answer = YES
18 Correct 0 ms 212 KB answer = YES
19 Correct 1 ms 316 KB answer = YES
20 Correct 0 ms 212 KB answer = YES
21 Correct 0 ms 212 KB answer = YES
22 Correct 0 ms 212 KB answer = NO
23 Correct 0 ms 212 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 320 KB answer = YES
4 Correct 1 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 0 ms 320 KB answer = YES
7 Correct 0 ms 212 KB answer = YES
8 Correct 0 ms 212 KB answer = YES
9 Correct 0 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 1 ms 316 KB answer = YES
12 Correct 0 ms 212 KB answer = NO
13 Correct 1 ms 212 KB answer = YES
14 Correct 0 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 320 KB answer = YES
17 Correct 0 ms 212 KB answer = YES
18 Correct 0 ms 212 KB answer = YES
19 Correct 1 ms 316 KB answer = YES
20 Correct 0 ms 212 KB answer = YES
21 Correct 0 ms 212 KB answer = YES
22 Correct 0 ms 212 KB answer = NO
23 Correct 0 ms 212 KB answer = NO
24 Correct 1 ms 324 KB answer = YES
25 Correct 0 ms 212 KB answer = YES
26 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 320 KB answer = YES
4 Correct 1 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 0 ms 320 KB answer = YES
7 Correct 0 ms 212 KB answer = YES
8 Correct 0 ms 212 KB answer = YES
9 Correct 0 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 1 ms 316 KB answer = YES
12 Correct 0 ms 212 KB answer = NO
13 Correct 1 ms 212 KB answer = YES
14 Correct 0 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 320 KB answer = YES
17 Correct 0 ms 212 KB answer = YES
18 Correct 0 ms 212 KB answer = YES
19 Correct 1 ms 316 KB answer = YES
20 Correct 0 ms 212 KB answer = YES
21 Correct 0 ms 212 KB answer = YES
22 Correct 0 ms 212 KB answer = NO
23 Correct 0 ms 212 KB answer = NO
24 Correct 1 ms 324 KB answer = YES
25 Correct 0 ms 212 KB answer = YES
26 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 320 KB answer = YES
4 Correct 1 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 0 ms 320 KB answer = YES
7 Correct 0 ms 212 KB answer = YES
8 Correct 0 ms 212 KB answer = YES
9 Correct 0 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 1 ms 316 KB answer = YES
12 Correct 0 ms 212 KB answer = NO
13 Correct 1 ms 212 KB answer = YES
14 Correct 0 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 320 KB answer = YES
17 Correct 0 ms 212 KB answer = YES
18 Correct 0 ms 212 KB answer = YES
19 Correct 1 ms 316 KB answer = YES
20 Correct 0 ms 212 KB answer = YES
21 Correct 0 ms 212 KB answer = YES
22 Correct 0 ms 212 KB answer = NO
23 Correct 0 ms 212 KB answer = NO
24 Correct 1 ms 324 KB answer = YES
25 Correct 0 ms 212 KB answer = YES
26 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 212 KB answer = YES
3 Correct 1 ms 320 KB answer = YES
4 Correct 1 ms 212 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Correct 0 ms 320 KB answer = YES
7 Correct 0 ms 212 KB answer = YES
8 Correct 0 ms 212 KB answer = YES
9 Correct 0 ms 212 KB answer = NO
10 Correct 1 ms 212 KB answer = YES
11 Correct 1 ms 316 KB answer = YES
12 Correct 0 ms 212 KB answer = NO
13 Correct 1 ms 212 KB answer = YES
14 Correct 0 ms 212 KB answer = YES
15 Correct 1 ms 212 KB answer = YES
16 Correct 1 ms 320 KB answer = YES
17 Correct 0 ms 212 KB answer = YES
18 Correct 0 ms 212 KB answer = YES
19 Correct 1 ms 316 KB answer = YES
20 Correct 0 ms 212 KB answer = YES
21 Correct 0 ms 212 KB answer = YES
22 Correct 0 ms 212 KB answer = NO
23 Correct 0 ms 212 KB answer = NO
24 Correct 1 ms 324 KB answer = YES
25 Correct 0 ms 212 KB answer = YES
26 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
27 Halted 0 ms 0 KB -