답안 #462606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
462606 2021-08-11T00:01:21 Z JovanB Graph (BOI20_graph) C++17
100 / 100
208 ms 22924 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
ld res[100005];
pair <ll, int> sta[100005];
vector <pair <int, int>> graf[100005];
bool visited[100005];
 
const int INF = 1000000000;
 
ld mora = -INF;
vector <int> vec;
 
void fail(){
    cout << "NO";
    exit(0);
}
 
bool isti(ld a, ld b){
    return abs(a-b) < 0.00001;
}
 
void dfs(int v){
    visited[v] = 1;
    vec.push_back(v);
    for(auto g : graf[v]){
        int c = g.first;
        int tr = g.second;
        if(visited[c]){
            if(sta[c].first + sta[v].first == 0 && sta[c].second + sta[v].second != tr) fail();
            else if(sta[c].first + sta[v].first){
                if(isti(mora, -INF)) mora = 1.0*(tr-sta[c].second-sta[v].second)/(sta[c].first+sta[v].first);
                if(!isti((sta[v].first+sta[c].first)*mora+sta[c].second+sta[v].second, tr)) fail();
            }
            continue;
        }
        sta[c].first = -sta[v].first, sta[c].second = tr-sta[v].second;
        dfs(c);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        graf[a].push_back({b, c});
        graf[b].push_back({a, c});
    }
    for(int i=1; i<=n; i++){
        if(!visited[i]){
            mora = -INF;
            sta[i] = {1, 0};
            vec.clear();
            dfs(i);
            if(isti(mora, -INF)){
                vector <int> g;
                for(auto c : vec){
                    if(sta[c].first) g.push_back(-sta[c].second/(1.0*sta[c].first));
                }
                sort(g.begin(), g.end());
                if(!g.empty()) mora = g[g.size()/2];
                else mora = 0;
                for(auto c : vec) res[c] = mora*sta[c].first + sta[c].second;
            }
            else{
                for(auto c : vec) res[c] = mora*sta[c].first + sta[c].second;
                for(auto c : vec){
                    for(auto g : graf[c]){
                        int v = g.first, tr = g.second;
                        if(!isti(tr, mora*(sta[c].first+sta[v].first)+sta[v].second+sta[c].second)) fail();
                    }
                }
            }
        }
    }
    cout << "YES\n";
    for(int i=1; i<=n; i++){
        cout << res[i] << " ";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB answer = YES
2 Correct 2 ms 2636 KB answer = YES
3 Correct 2 ms 2672 KB answer = YES
4 Correct 2 ms 2680 KB answer = NO
5 Correct 2 ms 2676 KB answer = YES
6 Correct 2 ms 2636 KB answer = YES
7 Correct 3 ms 2636 KB answer = YES
8 Correct 2 ms 2636 KB answer = YES
9 Correct 2 ms 2636 KB answer = NO
10 Correct 3 ms 2636 KB answer = YES
11 Correct 2 ms 2636 KB answer = YES
12 Correct 2 ms 2636 KB answer = NO
13 Correct 3 ms 2636 KB answer = YES
14 Correct 2 ms 2636 KB answer = YES
15 Correct 2 ms 2636 KB answer = YES
16 Correct 2 ms 2764 KB answer = YES
17 Correct 2 ms 2636 KB answer = YES
18 Correct 2 ms 2636 KB answer = YES
19 Correct 2 ms 2636 KB answer = YES
20 Correct 2 ms 2676 KB answer = YES
21 Correct 3 ms 2668 KB answer = YES
22 Correct 2 ms 2636 KB answer = NO
23 Correct 2 ms 2672 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB answer = YES
2 Correct 2 ms 2636 KB answer = YES
3 Correct 2 ms 2672 KB answer = YES
4 Correct 2 ms 2680 KB answer = NO
5 Correct 2 ms 2676 KB answer = YES
6 Correct 2 ms 2636 KB answer = YES
7 Correct 3 ms 2636 KB answer = YES
8 Correct 2 ms 2636 KB answer = YES
9 Correct 2 ms 2636 KB answer = NO
10 Correct 3 ms 2636 KB answer = YES
11 Correct 2 ms 2636 KB answer = YES
12 Correct 2 ms 2636 KB answer = NO
13 Correct 3 ms 2636 KB answer = YES
14 Correct 2 ms 2636 KB answer = YES
15 Correct 2 ms 2636 KB answer = YES
16 Correct 2 ms 2764 KB answer = YES
17 Correct 2 ms 2636 KB answer = YES
18 Correct 2 ms 2636 KB answer = YES
19 Correct 2 ms 2636 KB answer = YES
20 Correct 2 ms 2676 KB answer = YES
21 Correct 3 ms 2668 KB answer = YES
22 Correct 2 ms 2636 KB answer = NO
23 Correct 2 ms 2672 KB answer = NO
24 Correct 2 ms 2636 KB answer = YES
25 Correct 2 ms 2636 KB answer = YES
26 Correct 2 ms 2636 KB answer = YES
27 Correct 3 ms 2636 KB answer = YES
28 Correct 2 ms 2636 KB answer = YES
29 Correct 2 ms 2636 KB answer = YES
30 Correct 3 ms 2656 KB answer = NO
31 Correct 3 ms 2656 KB answer = YES
32 Correct 2 ms 2636 KB answer = YES
33 Correct 2 ms 2636 KB answer = YES
34 Correct 2 ms 2636 KB answer = YES
35 Correct 2 ms 2636 KB answer = YES
36 Correct 2 ms 2636 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB answer = YES
2 Correct 2 ms 2636 KB answer = YES
3 Correct 2 ms 2672 KB answer = YES
4 Correct 2 ms 2680 KB answer = NO
5 Correct 2 ms 2676 KB answer = YES
6 Correct 2 ms 2636 KB answer = YES
7 Correct 3 ms 2636 KB answer = YES
8 Correct 2 ms 2636 KB answer = YES
9 Correct 2 ms 2636 KB answer = NO
10 Correct 3 ms 2636 KB answer = YES
11 Correct 2 ms 2636 KB answer = YES
12 Correct 2 ms 2636 KB answer = NO
13 Correct 3 ms 2636 KB answer = YES
14 Correct 2 ms 2636 KB answer = YES
15 Correct 2 ms 2636 KB answer = YES
16 Correct 2 ms 2764 KB answer = YES
17 Correct 2 ms 2636 KB answer = YES
18 Correct 2 ms 2636 KB answer = YES
19 Correct 2 ms 2636 KB answer = YES
20 Correct 2 ms 2676 KB answer = YES
21 Correct 3 ms 2668 KB answer = YES
22 Correct 2 ms 2636 KB answer = NO
23 Correct 2 ms 2672 KB answer = NO
24 Correct 2 ms 2636 KB answer = YES
25 Correct 2 ms 2636 KB answer = YES
26 Correct 2 ms 2636 KB answer = YES
27 Correct 3 ms 2636 KB answer = YES
28 Correct 2 ms 2636 KB answer = YES
29 Correct 2 ms 2636 KB answer = YES
30 Correct 3 ms 2656 KB answer = NO
31 Correct 3 ms 2656 KB answer = YES
32 Correct 2 ms 2636 KB answer = YES
33 Correct 2 ms 2636 KB answer = YES
34 Correct 2 ms 2636 KB answer = YES
35 Correct 2 ms 2636 KB answer = YES
36 Correct 2 ms 2636 KB answer = YES
37 Correct 2 ms 2636 KB answer = YES
38 Correct 3 ms 2616 KB answer = YES
39 Correct 4 ms 2636 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 2 ms 2636 KB answer = NO
42 Correct 3 ms 2764 KB answer = YES
43 Correct 3 ms 2684 KB answer = YES
44 Correct 4 ms 2764 KB answer = YES
45 Correct 3 ms 2764 KB answer = YES
46 Correct 2 ms 2636 KB answer = YES
47 Correct 3 ms 2688 KB answer = YES
48 Correct 3 ms 2792 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB answer = YES
2 Correct 2 ms 2636 KB answer = YES
3 Correct 2 ms 2672 KB answer = YES
4 Correct 2 ms 2680 KB answer = NO
5 Correct 2 ms 2676 KB answer = YES
6 Correct 2 ms 2636 KB answer = YES
7 Correct 3 ms 2636 KB answer = YES
8 Correct 2 ms 2636 KB answer = YES
9 Correct 2 ms 2636 KB answer = NO
10 Correct 3 ms 2636 KB answer = YES
11 Correct 2 ms 2636 KB answer = YES
12 Correct 2 ms 2636 KB answer = NO
13 Correct 3 ms 2636 KB answer = YES
14 Correct 2 ms 2636 KB answer = YES
15 Correct 2 ms 2636 KB answer = YES
16 Correct 2 ms 2764 KB answer = YES
17 Correct 2 ms 2636 KB answer = YES
18 Correct 2 ms 2636 KB answer = YES
19 Correct 2 ms 2636 KB answer = YES
20 Correct 2 ms 2676 KB answer = YES
21 Correct 3 ms 2668 KB answer = YES
22 Correct 2 ms 2636 KB answer = NO
23 Correct 2 ms 2672 KB answer = NO
24 Correct 2 ms 2636 KB answer = YES
25 Correct 2 ms 2636 KB answer = YES
26 Correct 2 ms 2636 KB answer = YES
27 Correct 3 ms 2636 KB answer = YES
28 Correct 2 ms 2636 KB answer = YES
29 Correct 2 ms 2636 KB answer = YES
30 Correct 3 ms 2656 KB answer = NO
31 Correct 3 ms 2656 KB answer = YES
32 Correct 2 ms 2636 KB answer = YES
33 Correct 2 ms 2636 KB answer = YES
34 Correct 2 ms 2636 KB answer = YES
35 Correct 2 ms 2636 KB answer = YES
36 Correct 2 ms 2636 KB answer = YES
37 Correct 2 ms 2636 KB answer = YES
38 Correct 3 ms 2616 KB answer = YES
39 Correct 4 ms 2636 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 2 ms 2636 KB answer = NO
42 Correct 3 ms 2764 KB answer = YES
43 Correct 3 ms 2684 KB answer = YES
44 Correct 4 ms 2764 KB answer = YES
45 Correct 3 ms 2764 KB answer = YES
46 Correct 2 ms 2636 KB answer = YES
47 Correct 3 ms 2688 KB answer = YES
48 Correct 3 ms 2792 KB answer = YES
49 Correct 13 ms 3660 KB answer = YES
50 Correct 13 ms 3916 KB answer = YES
51 Correct 13 ms 4044 KB answer = YES
52 Correct 8 ms 3324 KB answer = NO
53 Correct 3 ms 2764 KB answer = YES
54 Correct 4 ms 2892 KB answer = YES
55 Correct 7 ms 3148 KB answer = YES
56 Correct 14 ms 3708 KB answer = YES
57 Correct 16 ms 3532 KB answer = YES
58 Correct 11 ms 3608 KB answer = YES
59 Correct 14 ms 3540 KB answer = YES
60 Correct 12 ms 3668 KB answer = YES
61 Correct 8 ms 3148 KB answer = YES
62 Correct 77 ms 9692 KB answer = NO
63 Correct 82 ms 10508 KB answer = YES
64 Correct 73 ms 10208 KB answer = NO
65 Correct 82 ms 10436 KB answer = YES
66 Correct 4 ms 2892 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB answer = YES
2 Correct 2 ms 2636 KB answer = YES
3 Correct 2 ms 2672 KB answer = YES
4 Correct 2 ms 2680 KB answer = NO
5 Correct 2 ms 2676 KB answer = YES
6 Correct 2 ms 2636 KB answer = YES
7 Correct 3 ms 2636 KB answer = YES
8 Correct 2 ms 2636 KB answer = YES
9 Correct 2 ms 2636 KB answer = NO
10 Correct 3 ms 2636 KB answer = YES
11 Correct 2 ms 2636 KB answer = YES
12 Correct 2 ms 2636 KB answer = NO
13 Correct 3 ms 2636 KB answer = YES
14 Correct 2 ms 2636 KB answer = YES
15 Correct 2 ms 2636 KB answer = YES
16 Correct 2 ms 2764 KB answer = YES
17 Correct 2 ms 2636 KB answer = YES
18 Correct 2 ms 2636 KB answer = YES
19 Correct 2 ms 2636 KB answer = YES
20 Correct 2 ms 2676 KB answer = YES
21 Correct 3 ms 2668 KB answer = YES
22 Correct 2 ms 2636 KB answer = NO
23 Correct 2 ms 2672 KB answer = NO
24 Correct 2 ms 2636 KB answer = YES
25 Correct 2 ms 2636 KB answer = YES
26 Correct 2 ms 2636 KB answer = YES
27 Correct 3 ms 2636 KB answer = YES
28 Correct 2 ms 2636 KB answer = YES
29 Correct 2 ms 2636 KB answer = YES
30 Correct 3 ms 2656 KB answer = NO
31 Correct 3 ms 2656 KB answer = YES
32 Correct 2 ms 2636 KB answer = YES
33 Correct 2 ms 2636 KB answer = YES
34 Correct 2 ms 2636 KB answer = YES
35 Correct 2 ms 2636 KB answer = YES
36 Correct 2 ms 2636 KB answer = YES
37 Correct 2 ms 2636 KB answer = YES
38 Correct 3 ms 2616 KB answer = YES
39 Correct 4 ms 2636 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 2 ms 2636 KB answer = NO
42 Correct 3 ms 2764 KB answer = YES
43 Correct 3 ms 2684 KB answer = YES
44 Correct 4 ms 2764 KB answer = YES
45 Correct 3 ms 2764 KB answer = YES
46 Correct 2 ms 2636 KB answer = YES
47 Correct 3 ms 2688 KB answer = YES
48 Correct 3 ms 2792 KB answer = YES
49 Correct 13 ms 3660 KB answer = YES
50 Correct 13 ms 3916 KB answer = YES
51 Correct 13 ms 4044 KB answer = YES
52 Correct 8 ms 3324 KB answer = NO
53 Correct 3 ms 2764 KB answer = YES
54 Correct 4 ms 2892 KB answer = YES
55 Correct 7 ms 3148 KB answer = YES
56 Correct 14 ms 3708 KB answer = YES
57 Correct 16 ms 3532 KB answer = YES
58 Correct 11 ms 3608 KB answer = YES
59 Correct 14 ms 3540 KB answer = YES
60 Correct 12 ms 3668 KB answer = YES
61 Correct 8 ms 3148 KB answer = YES
62 Correct 77 ms 9692 KB answer = NO
63 Correct 82 ms 10508 KB answer = YES
64 Correct 73 ms 10208 KB answer = NO
65 Correct 82 ms 10436 KB answer = YES
66 Correct 4 ms 2892 KB answer = YES
67 Correct 144 ms 18524 KB answer = YES
68 Correct 127 ms 18388 KB answer = YES
69 Correct 113 ms 18448 KB answer = YES
70 Correct 159 ms 22924 KB answer = YES
71 Correct 111 ms 18436 KB answer = YES
72 Correct 121 ms 12744 KB answer = YES
73 Correct 131 ms 12760 KB answer = YES
74 Correct 84 ms 12212 KB answer = YES
75 Correct 40 ms 8440 KB answer = NO
76 Correct 16 ms 3964 KB answer = YES
77 Correct 37 ms 5160 KB answer = YES
78 Correct 62 ms 7084 KB answer = YES
79 Correct 120 ms 11316 KB answer = YES
80 Correct 88 ms 12132 KB answer = YES
81 Correct 57 ms 12488 KB answer = NO
82 Correct 160 ms 18028 KB answer = YES
83 Correct 155 ms 18520 KB answer = YES
84 Correct 188 ms 18504 KB answer = YES
85 Correct 122 ms 18504 KB answer = YES
86 Correct 115 ms 18524 KB answer = YES
87 Correct 65 ms 12288 KB answer = NO
88 Correct 180 ms 14620 KB answer = YES
89 Correct 118 ms 11584 KB answer = YES
90 Correct 125 ms 11628 KB answer = YES
91 Correct 157 ms 11616 KB answer = YES
92 Correct 67 ms 7756 KB answer = YES
93 Correct 65 ms 7704 KB answer = YES
94 Correct 80 ms 15480 KB answer = NO
95 Correct 69 ms 10332 KB answer = NO
96 Correct 208 ms 20264 KB answer = YES
97 Correct 45 ms 15556 KB answer = NO