Submission #1024970

# Submission time Handle Problem Language Result Execution time Memory
1024970 2024-07-16T13:30:32 Z ach00 Graph (BOI20_graph) C++14
100 / 100
147 ms 24008 KB
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
#define A first
#define X second
#define EPS 0.00001
int n,m;
vector<ld> ans(100005, numeric_limits<ld>::max());
vector<vector<pair<int,int>>> adj; 
vector<pair<int,int>> prelim(100005, {0, 0});
vector<int> arrthing;
ld start_value = numeric_limits<ld>::max();
void explore(int v, int p) {
    if(prelim[v].X == 0) {
        prelim[v].X = 1;
    }
    int x = prelim[v].X;
    int a = prelim[v].A;
    if(a == 0) {
        arrthing.push_back(0);
    } else if(x == 1) {
        arrthing.push_back(-a);
    } else {
        arrthing.push_back(a);
    }
    for(auto &e : adj[v]) {
        if(start_value != numeric_limits<ld>::max()) return;
        int u = e.first;
        int c = e.second;
        if(u == p) continue;
        if(prelim[u].X == 0) {
            prelim[u].X = -1*x;
            prelim[u].A = c - a;
            explore(u, v);
        } else {
            if(prelim[u].X + x == 0) {
                if(prelim[u].A + a != c) {
                    cout << "NO";
                    exit(0);
                }
            } else {
                start_value = ((ld)x)*((ld)(c-a-prelim[u].A))/(2.0);
                return;
            }
        }
    }
}
void assign(int v) {
    for(auto &e : adj[v]) {
        int u = e.first;
        ld c = (ld)e.second;
        ld nans = c - ans[v];
        if(ans[u] != numeric_limits<ld>::max()) {
            if(abs(ans[u] - nans) < EPS) continue;
            cout << "NO";
            exit(0);
        } else {
            ans[u] = nans;
            assign(u);
        }
    }
}

int main() {
    cin >> n >> m;
    ans.resize(n);
    adj.resize(n);
    for(int i = 0; i < m; i++) {
        int a,b,c; cin >> a >> b >> c; a--; b--;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    for(int i = 0; i < n; i++) {
        if(ans[i] != numeric_limits<ld>::max()) continue;
        start_value = numeric_limits<ld>::max();
        arrthing = {};
        explore(i, -1);
        if(start_value != numeric_limits<ld>::max()) {
            ans[i] = start_value;
            assign(i);
        } else {
            sort(arrthing.begin(), arrthing.end());
            ans[i] = (arrthing.size() != 0) ? ((ld)(arrthing[(arrthing.size())/2] + arrthing[(arrthing.size()-1)/2]))/2.0 : 0;
            assign(i);
        }
    }
    cout << "YES\n";
    for(int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 2 ms 2652 KB answer = YES
3 Correct 2 ms 2564 KB answer = YES
4 Correct 1 ms 2648 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2652 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2648 KB answer = YES
9 Correct 2 ms 2652 KB answer = NO
10 Correct 1 ms 2652 KB answer = YES
11 Correct 1 ms 2652 KB answer = YES
12 Correct 1 ms 2652 KB answer = NO
13 Correct 1 ms 2652 KB answer = YES
14 Correct 1 ms 2652 KB answer = YES
15 Correct 1 ms 2800 KB answer = YES
16 Correct 1 ms 2652 KB answer = YES
17 Correct 1 ms 2652 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2800 KB answer = YES
21 Correct 1 ms 2652 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 1 ms 2652 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 2 ms 2652 KB answer = YES
3 Correct 2 ms 2564 KB answer = YES
4 Correct 1 ms 2648 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2652 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2648 KB answer = YES
9 Correct 2 ms 2652 KB answer = NO
10 Correct 1 ms 2652 KB answer = YES
11 Correct 1 ms 2652 KB answer = YES
12 Correct 1 ms 2652 KB answer = NO
13 Correct 1 ms 2652 KB answer = YES
14 Correct 1 ms 2652 KB answer = YES
15 Correct 1 ms 2800 KB answer = YES
16 Correct 1 ms 2652 KB answer = YES
17 Correct 1 ms 2652 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2800 KB answer = YES
21 Correct 1 ms 2652 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 1 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 1 ms 2648 KB answer = YES
26 Correct 1 ms 2652 KB answer = YES
27 Correct 2 ms 2652 KB answer = YES
28 Correct 2 ms 2812 KB answer = YES
29 Correct 1 ms 2652 KB answer = YES
30 Correct 1 ms 2652 KB answer = NO
31 Correct 1 ms 2652 KB answer = YES
32 Correct 2 ms 2652 KB answer = YES
33 Correct 1 ms 2652 KB answer = YES
34 Correct 1 ms 2652 KB answer = YES
35 Correct 1 ms 2652 KB answer = YES
36 Correct 1 ms 2652 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 2 ms 2652 KB answer = YES
3 Correct 2 ms 2564 KB answer = YES
4 Correct 1 ms 2648 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2652 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2648 KB answer = YES
9 Correct 2 ms 2652 KB answer = NO
10 Correct 1 ms 2652 KB answer = YES
11 Correct 1 ms 2652 KB answer = YES
12 Correct 1 ms 2652 KB answer = NO
13 Correct 1 ms 2652 KB answer = YES
14 Correct 1 ms 2652 KB answer = YES
15 Correct 1 ms 2800 KB answer = YES
16 Correct 1 ms 2652 KB answer = YES
17 Correct 1 ms 2652 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2800 KB answer = YES
21 Correct 1 ms 2652 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 1 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 1 ms 2648 KB answer = YES
26 Correct 1 ms 2652 KB answer = YES
27 Correct 2 ms 2652 KB answer = YES
28 Correct 2 ms 2812 KB answer = YES
29 Correct 1 ms 2652 KB answer = YES
30 Correct 1 ms 2652 KB answer = NO
31 Correct 1 ms 2652 KB answer = YES
32 Correct 2 ms 2652 KB answer = YES
33 Correct 1 ms 2652 KB answer = YES
34 Correct 1 ms 2652 KB answer = YES
35 Correct 1 ms 2652 KB answer = YES
36 Correct 1 ms 2652 KB answer = YES
37 Correct 2 ms 2652 KB answer = YES
38 Correct 1 ms 2716 KB answer = YES
39 Correct 2 ms 2648 KB answer = YES
40 Correct 2 ms 2652 KB answer = YES
41 Correct 2 ms 2652 KB answer = NO
42 Correct 2 ms 2648 KB answer = YES
43 Correct 2 ms 2828 KB answer = YES
44 Correct 2 ms 2652 KB answer = YES
45 Correct 2 ms 2652 KB answer = YES
46 Correct 2 ms 2784 KB answer = YES
47 Correct 2 ms 2652 KB answer = YES
48 Correct 2 ms 2652 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 2 ms 2652 KB answer = YES
3 Correct 2 ms 2564 KB answer = YES
4 Correct 1 ms 2648 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2652 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2648 KB answer = YES
9 Correct 2 ms 2652 KB answer = NO
10 Correct 1 ms 2652 KB answer = YES
11 Correct 1 ms 2652 KB answer = YES
12 Correct 1 ms 2652 KB answer = NO
13 Correct 1 ms 2652 KB answer = YES
14 Correct 1 ms 2652 KB answer = YES
15 Correct 1 ms 2800 KB answer = YES
16 Correct 1 ms 2652 KB answer = YES
17 Correct 1 ms 2652 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2800 KB answer = YES
21 Correct 1 ms 2652 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 1 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 1 ms 2648 KB answer = YES
26 Correct 1 ms 2652 KB answer = YES
27 Correct 2 ms 2652 KB answer = YES
28 Correct 2 ms 2812 KB answer = YES
29 Correct 1 ms 2652 KB answer = YES
30 Correct 1 ms 2652 KB answer = NO
31 Correct 1 ms 2652 KB answer = YES
32 Correct 2 ms 2652 KB answer = YES
33 Correct 1 ms 2652 KB answer = YES
34 Correct 1 ms 2652 KB answer = YES
35 Correct 1 ms 2652 KB answer = YES
36 Correct 1 ms 2652 KB answer = YES
37 Correct 2 ms 2652 KB answer = YES
38 Correct 1 ms 2716 KB answer = YES
39 Correct 2 ms 2648 KB answer = YES
40 Correct 2 ms 2652 KB answer = YES
41 Correct 2 ms 2652 KB answer = NO
42 Correct 2 ms 2648 KB answer = YES
43 Correct 2 ms 2828 KB answer = YES
44 Correct 2 ms 2652 KB answer = YES
45 Correct 2 ms 2652 KB answer = YES
46 Correct 2 ms 2784 KB answer = YES
47 Correct 2 ms 2652 KB answer = YES
48 Correct 2 ms 2652 KB answer = YES
49 Correct 9 ms 3420 KB answer = YES
50 Correct 11 ms 3932 KB answer = YES
51 Correct 10 ms 3928 KB answer = YES
52 Correct 6 ms 3416 KB answer = NO
53 Correct 3 ms 2648 KB answer = YES
54 Correct 3 ms 2908 KB answer = YES
55 Correct 6 ms 3164 KB answer = YES
56 Correct 10 ms 3600 KB answer = YES
57 Correct 14 ms 3420 KB answer = YES
58 Correct 9 ms 3416 KB answer = YES
59 Correct 9 ms 3420 KB answer = YES
60 Correct 11 ms 3420 KB answer = YES
61 Correct 5 ms 3164 KB answer = YES
62 Correct 89 ms 7872 KB answer = NO
63 Correct 89 ms 10072 KB answer = YES
64 Correct 86 ms 10100 KB answer = NO
65 Correct 92 ms 10064 KB answer = YES
66 Correct 3 ms 2908 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 2 ms 2652 KB answer = YES
3 Correct 2 ms 2564 KB answer = YES
4 Correct 1 ms 2648 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2652 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2648 KB answer = YES
9 Correct 2 ms 2652 KB answer = NO
10 Correct 1 ms 2652 KB answer = YES
11 Correct 1 ms 2652 KB answer = YES
12 Correct 1 ms 2652 KB answer = NO
13 Correct 1 ms 2652 KB answer = YES
14 Correct 1 ms 2652 KB answer = YES
15 Correct 1 ms 2800 KB answer = YES
16 Correct 1 ms 2652 KB answer = YES
17 Correct 1 ms 2652 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2800 KB answer = YES
21 Correct 1 ms 2652 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 1 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 1 ms 2648 KB answer = YES
26 Correct 1 ms 2652 KB answer = YES
27 Correct 2 ms 2652 KB answer = YES
28 Correct 2 ms 2812 KB answer = YES
29 Correct 1 ms 2652 KB answer = YES
30 Correct 1 ms 2652 KB answer = NO
31 Correct 1 ms 2652 KB answer = YES
32 Correct 2 ms 2652 KB answer = YES
33 Correct 1 ms 2652 KB answer = YES
34 Correct 1 ms 2652 KB answer = YES
35 Correct 1 ms 2652 KB answer = YES
36 Correct 1 ms 2652 KB answer = YES
37 Correct 2 ms 2652 KB answer = YES
38 Correct 1 ms 2716 KB answer = YES
39 Correct 2 ms 2648 KB answer = YES
40 Correct 2 ms 2652 KB answer = YES
41 Correct 2 ms 2652 KB answer = NO
42 Correct 2 ms 2648 KB answer = YES
43 Correct 2 ms 2828 KB answer = YES
44 Correct 2 ms 2652 KB answer = YES
45 Correct 2 ms 2652 KB answer = YES
46 Correct 2 ms 2784 KB answer = YES
47 Correct 2 ms 2652 KB answer = YES
48 Correct 2 ms 2652 KB answer = YES
49 Correct 9 ms 3420 KB answer = YES
50 Correct 11 ms 3932 KB answer = YES
51 Correct 10 ms 3928 KB answer = YES
52 Correct 6 ms 3416 KB answer = NO
53 Correct 3 ms 2648 KB answer = YES
54 Correct 3 ms 2908 KB answer = YES
55 Correct 6 ms 3164 KB answer = YES
56 Correct 10 ms 3600 KB answer = YES
57 Correct 14 ms 3420 KB answer = YES
58 Correct 9 ms 3416 KB answer = YES
59 Correct 9 ms 3420 KB answer = YES
60 Correct 11 ms 3420 KB answer = YES
61 Correct 5 ms 3164 KB answer = YES
62 Correct 89 ms 7872 KB answer = NO
63 Correct 89 ms 10072 KB answer = YES
64 Correct 86 ms 10100 KB answer = NO
65 Correct 92 ms 10064 KB answer = YES
66 Correct 3 ms 2908 KB answer = YES
67 Correct 105 ms 19672 KB answer = YES
68 Correct 97 ms 19884 KB answer = YES
69 Correct 92 ms 19664 KB answer = YES
70 Correct 143 ms 24008 KB answer = YES
71 Correct 94 ms 19744 KB answer = YES
72 Correct 99 ms 10924 KB answer = YES
73 Correct 85 ms 10712 KB answer = YES
74 Correct 56 ms 10328 KB answer = YES
75 Correct 36 ms 9808 KB answer = NO
76 Correct 12 ms 3676 KB answer = YES
77 Correct 27 ms 4696 KB answer = YES
78 Correct 39 ms 6252 KB answer = YES
79 Correct 73 ms 9672 KB answer = YES
80 Correct 60 ms 12500 KB answer = YES
81 Correct 59 ms 13528 KB answer = NO
82 Correct 89 ms 15316 KB answer = YES
83 Correct 127 ms 19896 KB answer = YES
84 Correct 103 ms 19688 KB answer = YES
85 Correct 88 ms 19668 KB answer = YES
86 Correct 88 ms 19668 KB answer = YES
87 Correct 60 ms 12624 KB answer = NO
88 Correct 111 ms 14296 KB answer = YES
89 Correct 91 ms 9864 KB answer = YES
90 Correct 98 ms 9768 KB answer = YES
91 Correct 94 ms 9808 KB answer = YES
92 Correct 46 ms 6840 KB answer = YES
93 Correct 40 ms 6736 KB answer = YES
94 Correct 62 ms 19412 KB answer = NO
95 Correct 56 ms 9496 KB answer = NO
96 Correct 147 ms 17076 KB answer = YES
97 Correct 53 ms 19440 KB answer = NO