Submission #342946

# Submission time Handle Problem Language Result Execution time Memory
342946 2021-01-03T09:02:00 Z mjhmjh1104 Graph (BOI20_graph) C++14
100 / 100
206 ms 27624 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n, m, cl[100006];
bool a[100006];
long long c[100006];
bool visited[100006];
vector<pair<int, int>> adj[100006];
vector<double> v[100006];
vector<int> colorList[100006];

int sg(bool x) {
    if (x) return 1;
    else return -1;
}

void dfs(int x, int color) {
    cl[x] = color;
    colorList[color].push_back(x);
    visited[x] = true;
    for (auto &i: adj[x]) {
        if (!visited[i.first]) {
            a[i.first] = !a[x];
            c[i.first] = i.second - c[x];
            dfs(i.first, color);
        } else {
            if (a[i.first] != a[x]) {
                if (c[i.first] + c[x] != i.second) {
                    puts("NO");
                    exit(0);
                }
            } else v[color].push_back((double)(i.second - c[i.first] - c[x]) / (sg(a[i.first]) + sg(a[x])));
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    while (m--) {
        int u, v, c;
        scanf("%d%d%d", &u, &v, &c);
        u--, v--;
        adj[u].push_back({ v, c });
        adj[v].push_back({ u, c });
    }
    a[0] = 1, c[0] = 0;
    int color = 0;
    for (int i = 0; i < n; i++) if (!visited[i]) dfs(i, color++);
    double res[100006] = {};
    for (int i = 0; i < color; i++) {
        if (v[i].empty()) {
            vector<long long> _a;
            for (auto &j: colorList[i]) _a.push_back(-c[j] * sg(a[j]));
            sort(_a.begin(), _a.end());
            for (auto &j: colorList[i]) res[j] = sg(a[j]) * _a[(int)_a.size() / 2] + c[j];
        } else {
            sort(v[i].begin(), v[i].end());
            v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
            if (v[i].size() != 1) {
                puts("NO");
                return 0;
            } else for (auto &j: colorList[i]) res[j] = sg(a[j]) * v[i][0] + c[j];
        }
    }
    puts("YES");
    for (int i = 0; i < n; i++) printf("%.8f ", res[i]);
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Graph.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |         scanf("%d%d%d", &u, &v, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB answer = YES
2 Correct 5 ms 8172 KB answer = YES
3 Correct 5 ms 8172 KB answer = YES
4 Correct 5 ms 7404 KB answer = NO
5 Correct 6 ms 8172 KB answer = YES
6 Correct 5 ms 8172 KB answer = YES
7 Correct 5 ms 8172 KB answer = YES
8 Correct 5 ms 8172 KB answer = YES
9 Correct 5 ms 7404 KB answer = NO
10 Correct 5 ms 8172 KB answer = YES
11 Correct 5 ms 8172 KB answer = YES
12 Correct 5 ms 7404 KB answer = NO
13 Correct 5 ms 8172 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8172 KB answer = YES
16 Correct 5 ms 8192 KB answer = YES
17 Correct 5 ms 8172 KB answer = YES
18 Correct 5 ms 8172 KB answer = YES
19 Correct 5 ms 8172 KB answer = YES
20 Correct 5 ms 8172 KB answer = YES
21 Correct 5 ms 8172 KB answer = YES
22 Correct 5 ms 7424 KB answer = NO
23 Correct 5 ms 7404 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB answer = YES
2 Correct 5 ms 8172 KB answer = YES
3 Correct 5 ms 8172 KB answer = YES
4 Correct 5 ms 7404 KB answer = NO
5 Correct 6 ms 8172 KB answer = YES
6 Correct 5 ms 8172 KB answer = YES
7 Correct 5 ms 8172 KB answer = YES
8 Correct 5 ms 8172 KB answer = YES
9 Correct 5 ms 7404 KB answer = NO
10 Correct 5 ms 8172 KB answer = YES
11 Correct 5 ms 8172 KB answer = YES
12 Correct 5 ms 7404 KB answer = NO
13 Correct 5 ms 8172 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8172 KB answer = YES
16 Correct 5 ms 8192 KB answer = YES
17 Correct 5 ms 8172 KB answer = YES
18 Correct 5 ms 8172 KB answer = YES
19 Correct 5 ms 8172 KB answer = YES
20 Correct 5 ms 8172 KB answer = YES
21 Correct 5 ms 8172 KB answer = YES
22 Correct 5 ms 7424 KB answer = NO
23 Correct 5 ms 7404 KB answer = NO
24 Correct 7 ms 8172 KB answer = YES
25 Correct 5 ms 8172 KB answer = YES
26 Correct 5 ms 8172 KB answer = YES
27 Correct 6 ms 8172 KB answer = YES
28 Correct 6 ms 8172 KB answer = YES
29 Correct 5 ms 8172 KB answer = YES
30 Correct 5 ms 7404 KB answer = NO
31 Correct 5 ms 8172 KB answer = YES
32 Correct 5 ms 8172 KB answer = YES
33 Correct 5 ms 8172 KB answer = YES
34 Correct 6 ms 8172 KB answer = YES
35 Correct 6 ms 8172 KB answer = YES
36 Correct 5 ms 8172 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB answer = YES
2 Correct 5 ms 8172 KB answer = YES
3 Correct 5 ms 8172 KB answer = YES
4 Correct 5 ms 7404 KB answer = NO
5 Correct 6 ms 8172 KB answer = YES
6 Correct 5 ms 8172 KB answer = YES
7 Correct 5 ms 8172 KB answer = YES
8 Correct 5 ms 8172 KB answer = YES
9 Correct 5 ms 7404 KB answer = NO
10 Correct 5 ms 8172 KB answer = YES
11 Correct 5 ms 8172 KB answer = YES
12 Correct 5 ms 7404 KB answer = NO
13 Correct 5 ms 8172 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8172 KB answer = YES
16 Correct 5 ms 8192 KB answer = YES
17 Correct 5 ms 8172 KB answer = YES
18 Correct 5 ms 8172 KB answer = YES
19 Correct 5 ms 8172 KB answer = YES
20 Correct 5 ms 8172 KB answer = YES
21 Correct 5 ms 8172 KB answer = YES
22 Correct 5 ms 7424 KB answer = NO
23 Correct 5 ms 7404 KB answer = NO
24 Correct 7 ms 8172 KB answer = YES
25 Correct 5 ms 8172 KB answer = YES
26 Correct 5 ms 8172 KB answer = YES
27 Correct 6 ms 8172 KB answer = YES
28 Correct 6 ms 8172 KB answer = YES
29 Correct 5 ms 8172 KB answer = YES
30 Correct 5 ms 7404 KB answer = NO
31 Correct 5 ms 8172 KB answer = YES
32 Correct 5 ms 8172 KB answer = YES
33 Correct 5 ms 8172 KB answer = YES
34 Correct 6 ms 8172 KB answer = YES
35 Correct 6 ms 8172 KB answer = YES
36 Correct 5 ms 8172 KB answer = YES
37 Correct 5 ms 8172 KB answer = YES
38 Correct 5 ms 8172 KB answer = YES
39 Correct 6 ms 8172 KB answer = YES
40 Correct 6 ms 8172 KB answer = YES
41 Correct 5 ms 7404 KB answer = NO
42 Correct 6 ms 8300 KB answer = YES
43 Correct 6 ms 8172 KB answer = YES
44 Correct 6 ms 8192 KB answer = YES
45 Correct 6 ms 8172 KB answer = YES
46 Correct 6 ms 8172 KB answer = YES
47 Correct 6 ms 8172 KB answer = YES
48 Correct 6 ms 8172 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB answer = YES
2 Correct 5 ms 8172 KB answer = YES
3 Correct 5 ms 8172 KB answer = YES
4 Correct 5 ms 7404 KB answer = NO
5 Correct 6 ms 8172 KB answer = YES
6 Correct 5 ms 8172 KB answer = YES
7 Correct 5 ms 8172 KB answer = YES
8 Correct 5 ms 8172 KB answer = YES
9 Correct 5 ms 7404 KB answer = NO
10 Correct 5 ms 8172 KB answer = YES
11 Correct 5 ms 8172 KB answer = YES
12 Correct 5 ms 7404 KB answer = NO
13 Correct 5 ms 8172 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8172 KB answer = YES
16 Correct 5 ms 8192 KB answer = YES
17 Correct 5 ms 8172 KB answer = YES
18 Correct 5 ms 8172 KB answer = YES
19 Correct 5 ms 8172 KB answer = YES
20 Correct 5 ms 8172 KB answer = YES
21 Correct 5 ms 8172 KB answer = YES
22 Correct 5 ms 7424 KB answer = NO
23 Correct 5 ms 7404 KB answer = NO
24 Correct 7 ms 8172 KB answer = YES
25 Correct 5 ms 8172 KB answer = YES
26 Correct 5 ms 8172 KB answer = YES
27 Correct 6 ms 8172 KB answer = YES
28 Correct 6 ms 8172 KB answer = YES
29 Correct 5 ms 8172 KB answer = YES
30 Correct 5 ms 7404 KB answer = NO
31 Correct 5 ms 8172 KB answer = YES
32 Correct 5 ms 8172 KB answer = YES
33 Correct 5 ms 8172 KB answer = YES
34 Correct 6 ms 8172 KB answer = YES
35 Correct 6 ms 8172 KB answer = YES
36 Correct 5 ms 8172 KB answer = YES
37 Correct 5 ms 8172 KB answer = YES
38 Correct 5 ms 8172 KB answer = YES
39 Correct 6 ms 8172 KB answer = YES
40 Correct 6 ms 8172 KB answer = YES
41 Correct 5 ms 7404 KB answer = NO
42 Correct 6 ms 8300 KB answer = YES
43 Correct 6 ms 8172 KB answer = YES
44 Correct 6 ms 8192 KB answer = YES
45 Correct 6 ms 8172 KB answer = YES
46 Correct 6 ms 8172 KB answer = YES
47 Correct 6 ms 8172 KB answer = YES
48 Correct 6 ms 8172 KB answer = YES
49 Correct 13 ms 8988 KB answer = YES
50 Correct 14 ms 9452 KB answer = YES
51 Correct 14 ms 9436 KB answer = YES
52 Correct 11 ms 8044 KB answer = NO
53 Correct 7 ms 8172 KB answer = YES
54 Correct 9 ms 8300 KB answer = YES
55 Correct 10 ms 8556 KB answer = YES
56 Correct 13 ms 8940 KB answer = YES
57 Correct 13 ms 8812 KB answer = YES
58 Correct 12 ms 8812 KB answer = YES
59 Correct 12 ms 8812 KB answer = YES
60 Correct 13 ms 8940 KB answer = YES
61 Correct 9 ms 8556 KB answer = YES
62 Correct 103 ms 12140 KB answer = NO
63 Correct 103 ms 15360 KB answer = YES
64 Correct 104 ms 15308 KB answer = NO
65 Correct 88 ms 15360 KB answer = YES
66 Correct 7 ms 8320 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8172 KB answer = YES
2 Correct 5 ms 8172 KB answer = YES
3 Correct 5 ms 8172 KB answer = YES
4 Correct 5 ms 7404 KB answer = NO
5 Correct 6 ms 8172 KB answer = YES
6 Correct 5 ms 8172 KB answer = YES
7 Correct 5 ms 8172 KB answer = YES
8 Correct 5 ms 8172 KB answer = YES
9 Correct 5 ms 7404 KB answer = NO
10 Correct 5 ms 8172 KB answer = YES
11 Correct 5 ms 8172 KB answer = YES
12 Correct 5 ms 7404 KB answer = NO
13 Correct 5 ms 8172 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8172 KB answer = YES
16 Correct 5 ms 8192 KB answer = YES
17 Correct 5 ms 8172 KB answer = YES
18 Correct 5 ms 8172 KB answer = YES
19 Correct 5 ms 8172 KB answer = YES
20 Correct 5 ms 8172 KB answer = YES
21 Correct 5 ms 8172 KB answer = YES
22 Correct 5 ms 7424 KB answer = NO
23 Correct 5 ms 7404 KB answer = NO
24 Correct 7 ms 8172 KB answer = YES
25 Correct 5 ms 8172 KB answer = YES
26 Correct 5 ms 8172 KB answer = YES
27 Correct 6 ms 8172 KB answer = YES
28 Correct 6 ms 8172 KB answer = YES
29 Correct 5 ms 8172 KB answer = YES
30 Correct 5 ms 7404 KB answer = NO
31 Correct 5 ms 8172 KB answer = YES
32 Correct 5 ms 8172 KB answer = YES
33 Correct 5 ms 8172 KB answer = YES
34 Correct 6 ms 8172 KB answer = YES
35 Correct 6 ms 8172 KB answer = YES
36 Correct 5 ms 8172 KB answer = YES
37 Correct 5 ms 8172 KB answer = YES
38 Correct 5 ms 8172 KB answer = YES
39 Correct 6 ms 8172 KB answer = YES
40 Correct 6 ms 8172 KB answer = YES
41 Correct 5 ms 7404 KB answer = NO
42 Correct 6 ms 8300 KB answer = YES
43 Correct 6 ms 8172 KB answer = YES
44 Correct 6 ms 8192 KB answer = YES
45 Correct 6 ms 8172 KB answer = YES
46 Correct 6 ms 8172 KB answer = YES
47 Correct 6 ms 8172 KB answer = YES
48 Correct 6 ms 8172 KB answer = YES
49 Correct 13 ms 8988 KB answer = YES
50 Correct 14 ms 9452 KB answer = YES
51 Correct 14 ms 9436 KB answer = YES
52 Correct 11 ms 8044 KB answer = NO
53 Correct 7 ms 8172 KB answer = YES
54 Correct 9 ms 8300 KB answer = YES
55 Correct 10 ms 8556 KB answer = YES
56 Correct 13 ms 8940 KB answer = YES
57 Correct 13 ms 8812 KB answer = YES
58 Correct 12 ms 8812 KB answer = YES
59 Correct 12 ms 8812 KB answer = YES
60 Correct 13 ms 8940 KB answer = YES
61 Correct 9 ms 8556 KB answer = YES
62 Correct 103 ms 12140 KB answer = NO
63 Correct 103 ms 15360 KB answer = YES
64 Correct 104 ms 15308 KB answer = NO
65 Correct 88 ms 15360 KB answer = YES
66 Correct 7 ms 8320 KB answer = YES
67 Correct 95 ms 23916 KB answer = YES
68 Correct 88 ms 23664 KB answer = YES
69 Correct 82 ms 23660 KB answer = YES
70 Correct 127 ms 27624 KB answer = YES
71 Correct 96 ms 23648 KB answer = YES
72 Correct 118 ms 14928 KB answer = YES
73 Correct 103 ms 14948 KB answer = YES
74 Correct 71 ms 17136 KB answer = YES
75 Correct 36 ms 12908 KB answer = NO
76 Correct 18 ms 9160 KB answer = YES
77 Correct 26 ms 9892 KB answer = YES
78 Correct 44 ms 11160 KB answer = YES
79 Correct 89 ms 13928 KB answer = YES
80 Correct 69 ms 17128 KB answer = YES
81 Correct 59 ms 17260 KB answer = NO
82 Correct 112 ms 23148 KB answer = YES
83 Correct 138 ms 23788 KB answer = YES
84 Correct 126 ms 23768 KB answer = YES
85 Correct 120 ms 23768 KB answer = YES
86 Correct 90 ms 23788 KB answer = YES
87 Correct 80 ms 14828 KB answer = NO
88 Correct 125 ms 18320 KB answer = YES
89 Correct 101 ms 15340 KB answer = YES
90 Correct 113 ms 15340 KB answer = YES
91 Correct 123 ms 15340 KB answer = YES
92 Correct 51 ms 11624 KB answer = YES
93 Correct 51 ms 11624 KB answer = YES
94 Correct 81 ms 21740 KB answer = NO
95 Correct 86 ms 14188 KB answer = NO
96 Correct 206 ms 23776 KB answer = YES
97 Correct 49 ms 21740 KB answer = NO