Submission #254808

# Submission time Handle Problem Language Result Execution time Memory
254808 2020-07-30T15:54:31 Z imeimi2000 Graph (BOI20_graph) C++17
100 / 100
178 ms 18548 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

void fail() {
    printf("NO\n");
    exit(0);
}

int n, m;
vector<pii> edge[100001];
bool vis[100001];

int a[100001], y[100001], b[100001];
vector<int> lst[100001];
void dfs(int x) {
    lst[y[x]].push_back(x);
    vis[x] = 1;
    for (auto [i, c] : edge[x]) {
        if (vis[i]) continue;
        a[i] = -a[x];
        y[i] = y[x];
        b[i] = c - b[x];
        dfs(i);
    }
}

bool ch[100001];
int ans[100001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].emplace_back(b, c);
        edge[b].emplace_back(a, c);
    }
    for (int i = 1; i <= n; ++i) {
        if (vis[i]) continue;
        a[i] = 1;
        y[i] = i;
        b[i] = 0;
        dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        for (auto [j, c] : edge[i]) {
            int A = a[i] + a[j];
            int Y = y[i];
            int B = b[i] + b[j];
            //AY + B = c;
            if (A) {
                int v = 2 * (c - B) / A;
                if (ch[Y] && v != ans[Y]) fail();
                ch[Y] = 1;
                ans[Y] = v;
            }
            else if (B != c) fail();
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (lst[i].empty()) continue;
        if (ch[i]) {
            for (int j : lst[i]) {
                if (i == j) continue;
                ans[j] = a[j] * ans[i] + 2 * b[j];
            }
        }
        else {
            vector<int> mid;
            for (int j : lst[i]) {
                mid.push_back(-b[j] / a[j]);
            }
            sort(mid.begin(), mid.end());
            int x = mid[mid.size() / 2];
            for (int j : lst[i]) {
                ans[j] = 2 * (a[j] * x + b[j]);
            }
        }
    }
    printf("YES\n");
    for (int i = 1; i <= n; ++i) {
        if (ans[i] < 0) printf("-");
        printf("%d.%d%c", abs(ans[i]) / 2, 5 * (ans[i] & 1), "\n "[i < n]);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB answer = YES
2 Correct 3 ms 4992 KB answer = YES
3 Correct 3 ms 4992 KB answer = YES
4 Correct 3 ms 4992 KB answer = NO
5 Correct 3 ms 4992 KB answer = YES
6 Correct 3 ms 4992 KB answer = YES
7 Correct 3 ms 4992 KB answer = YES
8 Correct 3 ms 4992 KB answer = YES
9 Correct 3 ms 4992 KB answer = NO
10 Correct 4 ms 4992 KB answer = YES
11 Correct 4 ms 4992 KB answer = YES
12 Correct 3 ms 4992 KB answer = NO
13 Correct 3 ms 4992 KB answer = YES
14 Correct 3 ms 5040 KB answer = YES
15 Correct 3 ms 4992 KB answer = YES
16 Correct 3 ms 4992 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 4992 KB answer = YES
19 Correct 3 ms 4992 KB answer = YES
20 Correct 3 ms 4992 KB answer = YES
21 Correct 3 ms 4992 KB answer = YES
22 Correct 3 ms 4992 KB answer = NO
23 Correct 3 ms 4992 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB answer = YES
2 Correct 3 ms 4992 KB answer = YES
3 Correct 3 ms 4992 KB answer = YES
4 Correct 3 ms 4992 KB answer = NO
5 Correct 3 ms 4992 KB answer = YES
6 Correct 3 ms 4992 KB answer = YES
7 Correct 3 ms 4992 KB answer = YES
8 Correct 3 ms 4992 KB answer = YES
9 Correct 3 ms 4992 KB answer = NO
10 Correct 4 ms 4992 KB answer = YES
11 Correct 4 ms 4992 KB answer = YES
12 Correct 3 ms 4992 KB answer = NO
13 Correct 3 ms 4992 KB answer = YES
14 Correct 3 ms 5040 KB answer = YES
15 Correct 3 ms 4992 KB answer = YES
16 Correct 3 ms 4992 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 4992 KB answer = YES
19 Correct 3 ms 4992 KB answer = YES
20 Correct 3 ms 4992 KB answer = YES
21 Correct 3 ms 4992 KB answer = YES
22 Correct 3 ms 4992 KB answer = NO
23 Correct 3 ms 4992 KB answer = NO
24 Correct 3 ms 4992 KB answer = YES
25 Correct 4 ms 4992 KB answer = YES
26 Correct 4 ms 4992 KB answer = YES
27 Correct 4 ms 4992 KB answer = YES
28 Correct 3 ms 4992 KB answer = YES
29 Correct 3 ms 4992 KB answer = YES
30 Correct 3 ms 4992 KB answer = NO
31 Correct 4 ms 5120 KB answer = YES
32 Correct 3 ms 5024 KB answer = YES
33 Correct 4 ms 4992 KB answer = YES
34 Correct 4 ms 4992 KB answer = YES
35 Correct 3 ms 4992 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB answer = YES
2 Correct 3 ms 4992 KB answer = YES
3 Correct 3 ms 4992 KB answer = YES
4 Correct 3 ms 4992 KB answer = NO
5 Correct 3 ms 4992 KB answer = YES
6 Correct 3 ms 4992 KB answer = YES
7 Correct 3 ms 4992 KB answer = YES
8 Correct 3 ms 4992 KB answer = YES
9 Correct 3 ms 4992 KB answer = NO
10 Correct 4 ms 4992 KB answer = YES
11 Correct 4 ms 4992 KB answer = YES
12 Correct 3 ms 4992 KB answer = NO
13 Correct 3 ms 4992 KB answer = YES
14 Correct 3 ms 5040 KB answer = YES
15 Correct 3 ms 4992 KB answer = YES
16 Correct 3 ms 4992 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 4992 KB answer = YES
19 Correct 3 ms 4992 KB answer = YES
20 Correct 3 ms 4992 KB answer = YES
21 Correct 3 ms 4992 KB answer = YES
22 Correct 3 ms 4992 KB answer = NO
23 Correct 3 ms 4992 KB answer = NO
24 Correct 3 ms 4992 KB answer = YES
25 Correct 4 ms 4992 KB answer = YES
26 Correct 4 ms 4992 KB answer = YES
27 Correct 4 ms 4992 KB answer = YES
28 Correct 3 ms 4992 KB answer = YES
29 Correct 3 ms 4992 KB answer = YES
30 Correct 3 ms 4992 KB answer = NO
31 Correct 4 ms 5120 KB answer = YES
32 Correct 3 ms 5024 KB answer = YES
33 Correct 4 ms 4992 KB answer = YES
34 Correct 4 ms 4992 KB answer = YES
35 Correct 3 ms 4992 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 4 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 5 ms 5120 KB answer = YES
41 Correct 3 ms 5120 KB answer = NO
42 Correct 5 ms 5120 KB answer = YES
43 Correct 4 ms 5120 KB answer = YES
44 Correct 5 ms 5120 KB answer = YES
45 Correct 5 ms 5120 KB answer = YES
46 Correct 3 ms 5120 KB answer = YES
47 Correct 3 ms 5120 KB answer = YES
48 Correct 4 ms 5120 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB answer = YES
2 Correct 3 ms 4992 KB answer = YES
3 Correct 3 ms 4992 KB answer = YES
4 Correct 3 ms 4992 KB answer = NO
5 Correct 3 ms 4992 KB answer = YES
6 Correct 3 ms 4992 KB answer = YES
7 Correct 3 ms 4992 KB answer = YES
8 Correct 3 ms 4992 KB answer = YES
9 Correct 3 ms 4992 KB answer = NO
10 Correct 4 ms 4992 KB answer = YES
11 Correct 4 ms 4992 KB answer = YES
12 Correct 3 ms 4992 KB answer = NO
13 Correct 3 ms 4992 KB answer = YES
14 Correct 3 ms 5040 KB answer = YES
15 Correct 3 ms 4992 KB answer = YES
16 Correct 3 ms 4992 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 4992 KB answer = YES
19 Correct 3 ms 4992 KB answer = YES
20 Correct 3 ms 4992 KB answer = YES
21 Correct 3 ms 4992 KB answer = YES
22 Correct 3 ms 4992 KB answer = NO
23 Correct 3 ms 4992 KB answer = NO
24 Correct 3 ms 4992 KB answer = YES
25 Correct 4 ms 4992 KB answer = YES
26 Correct 4 ms 4992 KB answer = YES
27 Correct 4 ms 4992 KB answer = YES
28 Correct 3 ms 4992 KB answer = YES
29 Correct 3 ms 4992 KB answer = YES
30 Correct 3 ms 4992 KB answer = NO
31 Correct 4 ms 5120 KB answer = YES
32 Correct 3 ms 5024 KB answer = YES
33 Correct 4 ms 4992 KB answer = YES
34 Correct 4 ms 4992 KB answer = YES
35 Correct 3 ms 4992 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 4 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 5 ms 5120 KB answer = YES
41 Correct 3 ms 5120 KB answer = NO
42 Correct 5 ms 5120 KB answer = YES
43 Correct 4 ms 5120 KB answer = YES
44 Correct 5 ms 5120 KB answer = YES
45 Correct 5 ms 5120 KB answer = YES
46 Correct 3 ms 5120 KB answer = YES
47 Correct 3 ms 5120 KB answer = YES
48 Correct 4 ms 5120 KB answer = YES
49 Correct 11 ms 5760 KB answer = YES
50 Correct 10 ms 6016 KB answer = YES
51 Correct 10 ms 6016 KB answer = YES
52 Correct 7 ms 5888 KB answer = NO
53 Correct 4 ms 5120 KB answer = YES
54 Correct 5 ms 5248 KB answer = YES
55 Correct 7 ms 5376 KB answer = YES
56 Correct 10 ms 5760 KB answer = YES
57 Correct 11 ms 5760 KB answer = YES
58 Correct 9 ms 5632 KB answer = YES
59 Correct 10 ms 5632 KB answer = YES
60 Correct 9 ms 5760 KB answer = YES
61 Correct 6 ms 5376 KB answer = YES
62 Correct 68 ms 10232 KB answer = NO
63 Correct 70 ms 10232 KB answer = YES
64 Correct 63 ms 10232 KB answer = NO
65 Correct 72 ms 10232 KB answer = YES
66 Correct 5 ms 5120 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB answer = YES
2 Correct 3 ms 4992 KB answer = YES
3 Correct 3 ms 4992 KB answer = YES
4 Correct 3 ms 4992 KB answer = NO
5 Correct 3 ms 4992 KB answer = YES
6 Correct 3 ms 4992 KB answer = YES
7 Correct 3 ms 4992 KB answer = YES
8 Correct 3 ms 4992 KB answer = YES
9 Correct 3 ms 4992 KB answer = NO
10 Correct 4 ms 4992 KB answer = YES
11 Correct 4 ms 4992 KB answer = YES
12 Correct 3 ms 4992 KB answer = NO
13 Correct 3 ms 4992 KB answer = YES
14 Correct 3 ms 5040 KB answer = YES
15 Correct 3 ms 4992 KB answer = YES
16 Correct 3 ms 4992 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 4992 KB answer = YES
19 Correct 3 ms 4992 KB answer = YES
20 Correct 3 ms 4992 KB answer = YES
21 Correct 3 ms 4992 KB answer = YES
22 Correct 3 ms 4992 KB answer = NO
23 Correct 3 ms 4992 KB answer = NO
24 Correct 3 ms 4992 KB answer = YES
25 Correct 4 ms 4992 KB answer = YES
26 Correct 4 ms 4992 KB answer = YES
27 Correct 4 ms 4992 KB answer = YES
28 Correct 3 ms 4992 KB answer = YES
29 Correct 3 ms 4992 KB answer = YES
30 Correct 3 ms 4992 KB answer = NO
31 Correct 4 ms 5120 KB answer = YES
32 Correct 3 ms 5024 KB answer = YES
33 Correct 4 ms 4992 KB answer = YES
34 Correct 4 ms 4992 KB answer = YES
35 Correct 3 ms 4992 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 4 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 5 ms 5120 KB answer = YES
41 Correct 3 ms 5120 KB answer = NO
42 Correct 5 ms 5120 KB answer = YES
43 Correct 4 ms 5120 KB answer = YES
44 Correct 5 ms 5120 KB answer = YES
45 Correct 5 ms 5120 KB answer = YES
46 Correct 3 ms 5120 KB answer = YES
47 Correct 3 ms 5120 KB answer = YES
48 Correct 4 ms 5120 KB answer = YES
49 Correct 11 ms 5760 KB answer = YES
50 Correct 10 ms 6016 KB answer = YES
51 Correct 10 ms 6016 KB answer = YES
52 Correct 7 ms 5888 KB answer = NO
53 Correct 4 ms 5120 KB answer = YES
54 Correct 5 ms 5248 KB answer = YES
55 Correct 7 ms 5376 KB answer = YES
56 Correct 10 ms 5760 KB answer = YES
57 Correct 11 ms 5760 KB answer = YES
58 Correct 9 ms 5632 KB answer = YES
59 Correct 10 ms 5632 KB answer = YES
60 Correct 9 ms 5760 KB answer = YES
61 Correct 6 ms 5376 KB answer = YES
62 Correct 68 ms 10232 KB answer = NO
63 Correct 70 ms 10232 KB answer = YES
64 Correct 63 ms 10232 KB answer = NO
65 Correct 72 ms 10232 KB answer = YES
66 Correct 5 ms 5120 KB answer = YES
67 Correct 72 ms 15592 KB answer = YES
68 Correct 66 ms 15476 KB answer = YES
69 Correct 66 ms 15472 KB answer = YES
70 Correct 108 ms 18548 KB answer = YES
71 Correct 68 ms 15468 KB answer = YES
72 Correct 82 ms 11376 KB answer = YES
73 Correct 76 ms 11376 KB answer = YES
74 Correct 47 ms 11380 KB answer = YES
75 Correct 36 ms 10740 KB answer = NO
76 Correct 10 ms 5888 KB answer = YES
77 Correct 30 ms 6684 KB answer = YES
78 Correct 34 ms 7884 KB answer = YES
79 Correct 78 ms 10528 KB answer = YES
80 Correct 54 ms 11384 KB answer = YES
81 Correct 73 ms 12400 KB answer = NO
82 Correct 81 ms 15216 KB answer = YES
83 Correct 99 ms 15728 KB answer = YES
84 Correct 99 ms 15588 KB answer = YES
85 Correct 70 ms 15592 KB answer = YES
86 Correct 74 ms 15728 KB answer = YES
87 Correct 70 ms 11640 KB answer = NO
88 Correct 91 ms 12916 KB answer = YES
89 Correct 85 ms 11256 KB answer = YES
90 Correct 76 ms 11256 KB answer = YES
91 Correct 112 ms 11284 KB answer = YES
92 Correct 43 ms 8312 KB answer = YES
93 Correct 36 ms 8312 KB answer = YES
94 Correct 90 ms 14704 KB answer = NO
95 Correct 63 ms 10616 KB answer = NO
96 Correct 178 ms 16644 KB answer = YES
97 Correct 49 ms 14576 KB answer = NO