답안 #557090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557090 2022-05-04T17:42:26 Z proma Graph (BOI20_graph) C++17
100 / 100
146 ms 22120 KB
#include <bits/stdc++.h>

//#define int long long
#define endl "\n"
#define see(x) cout<<#x<<"="<<x<<"\n";

using namespace std;

const int N = 1e5+5;
const int INF = 1e9;

int n, m, used[N], val[N], s[N];
vector <pair <int, int>> g[N];
vector <int> visited;
double x, res[N];

void dfs(int v, int p = 0) {
    used[v] = 1;
    visited.push_back(v);
    for (auto i: g[v]) {
        if (i.first == p) continue;
        if (used[i.first] and s[i.first] == s[v] and x == INF) {
            x = (i.second - val[i.first] - val[v]) / 2.0 * s[v];
        }
        else if (!used[i.first]) {
            s[i.first] = -s[v];
            val[i.first] = i.second - val[v];
            dfs(i.first, v);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
*/

    cin >> n >> m;

    for (int i = 0; i < m; i ++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    for (int i = 1; i <= n; i ++) {
        if (!used[i]) {
            x = INF;
            s[i] = 1;
            val[i] = 0;
            visited.clear();
            dfs(i);
            if (x == INF) {
                vector <int> v;
                for (auto i: visited) {
                    v.push_back(val[i] * (-s[i]));
                }
                sort(v.begin(), v.end());
                x = v[int(v.size())/2];
            }
            for (auto i: visited) {
                res[i] = s[i] * x + val[i];
            }
        }
    }

    for (int i = 1; i <= n; i ++) {
        for (auto j: g[i]) {
            if (res[i] + res[j.first] != j.second) {
                cout << "NO\n";
                return 0;
            }
        }
    }

    cout << "YES\n";
    for (int i = 1; i <= n; i ++) {
        cout << res[i] << " ";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 1 ms 2680 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2684 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 1 ms 2680 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2684 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2692 KB answer = YES
29 Correct 1 ms 2692 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 1 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 1 ms 2688 KB answer = YES
35 Correct 3 ms 2684 KB answer = YES
36 Correct 2 ms 2684 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 1 ms 2680 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2684 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2692 KB answer = YES
29 Correct 1 ms 2692 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 1 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 1 ms 2688 KB answer = YES
35 Correct 3 ms 2684 KB answer = YES
36 Correct 2 ms 2684 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2772 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 2 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 1 ms 2680 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2684 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2692 KB answer = YES
29 Correct 1 ms 2692 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 1 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 1 ms 2688 KB answer = YES
35 Correct 3 ms 2684 KB answer = YES
36 Correct 2 ms 2684 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2772 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 2 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
49 Correct 9 ms 3540 KB answer = YES
50 Correct 9 ms 3796 KB answer = YES
51 Correct 10 ms 3924 KB answer = YES
52 Correct 6 ms 3852 KB answer = NO
53 Correct 2 ms 2700 KB answer = YES
54 Correct 3 ms 2900 KB answer = YES
55 Correct 5 ms 3084 KB answer = YES
56 Correct 9 ms 3524 KB answer = YES
57 Correct 9 ms 3412 KB answer = YES
58 Correct 8 ms 3412 KB answer = YES
59 Correct 8 ms 3344 KB answer = YES
60 Correct 9 ms 3464 KB answer = YES
61 Correct 5 ms 3108 KB answer = YES
62 Correct 53 ms 10384 KB answer = NO
63 Correct 54 ms 10436 KB answer = YES
64 Correct 56 ms 10440 KB answer = NO
65 Correct 57 ms 10524 KB answer = YES
66 Correct 3 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 1 ms 2680 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2684 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2692 KB answer = YES
29 Correct 1 ms 2692 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 1 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 1 ms 2688 KB answer = YES
35 Correct 3 ms 2684 KB answer = YES
36 Correct 2 ms 2684 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2772 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 2 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
49 Correct 9 ms 3540 KB answer = YES
50 Correct 9 ms 3796 KB answer = YES
51 Correct 10 ms 3924 KB answer = YES
52 Correct 6 ms 3852 KB answer = NO
53 Correct 2 ms 2700 KB answer = YES
54 Correct 3 ms 2900 KB answer = YES
55 Correct 5 ms 3084 KB answer = YES
56 Correct 9 ms 3524 KB answer = YES
57 Correct 9 ms 3412 KB answer = YES
58 Correct 8 ms 3412 KB answer = YES
59 Correct 8 ms 3344 KB answer = YES
60 Correct 9 ms 3464 KB answer = YES
61 Correct 5 ms 3108 KB answer = YES
62 Correct 53 ms 10384 KB answer = NO
63 Correct 54 ms 10436 KB answer = YES
64 Correct 56 ms 10440 KB answer = NO
65 Correct 57 ms 10524 KB answer = YES
66 Correct 3 ms 2772 KB answer = YES
67 Correct 81 ms 17652 KB answer = YES
68 Correct 73 ms 17544 KB answer = YES
69 Correct 74 ms 17612 KB answer = YES
70 Correct 105 ms 22120 KB answer = YES
71 Correct 81 ms 17860 KB answer = YES
72 Correct 85 ms 10416 KB answer = YES
73 Correct 85 ms 10440 KB answer = YES
74 Correct 55 ms 11432 KB answer = YES
75 Correct 28 ms 11240 KB answer = NO
76 Correct 11 ms 3668 KB answer = YES
77 Correct 21 ms 4668 KB answer = YES
78 Correct 34 ms 6036 KB answer = YES
79 Correct 68 ms 9352 KB answer = YES
80 Correct 57 ms 11468 KB answer = YES
81 Correct 44 ms 13580 KB answer = NO
82 Correct 96 ms 17176 KB answer = YES
83 Correct 102 ms 17860 KB answer = YES
84 Correct 95 ms 17708 KB answer = YES
85 Correct 84 ms 17752 KB answer = YES
86 Correct 75 ms 17668 KB answer = YES
87 Correct 52 ms 11992 KB answer = NO
88 Correct 101 ms 13072 KB answer = YES
89 Correct 81 ms 9316 KB answer = YES
90 Correct 79 ms 9284 KB answer = YES
91 Correct 92 ms 9324 KB answer = YES
92 Correct 42 ms 6684 KB answer = YES
93 Correct 41 ms 6608 KB answer = YES
94 Correct 59 ms 17428 KB answer = NO
95 Correct 49 ms 9172 KB answer = NO
96 Correct 146 ms 19072 KB answer = YES
97 Correct 40 ms 17456 KB answer = NO