답안 #1095660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095660 2024-10-02T20:18:36 Z Tymond Graph (BOI20_graph) C++17
100 / 100
103 ms 26716 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int MAXN = 1e5 + 7;
vector<pii> g[MAXN];
int vis[MAXN];
pii val[MAXN];
ld res[MAXN];
int n, m;
vector<pair<pii, pii>> e;
vi vec;

void dfs(int v){
    vis[v] = 1;
    vec.pb(v);
    for(auto [u, c] : g[v]){
        if(!vis[u]){
            val[u] = mp(-val[v].fi, c - val[v].se);
            dfs(u);
        }else{
            if(mp(-val[v].fi, c - val[v].se) != val[u]){
                e.pb({val[u], mp(-val[v].fi, c - val[v].se)});
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        g[u].pb({v, c});
        g[v].pb({u, c});
    }

    for(int j = 1; j <= n; j++){
        if(!vis[j]){
            val[j] = {1, 0};
            e.clear();
            vec.clear();
            dfs(j);

            pii x = mp((int)-1e9, (int)-1e9);
            for(auto [u, v] : e){
                int mn = min(u.fi, v.fi);
                u.fi -= mn;
                v.fi -= mn;
                if(max(u.fi, v.fi) == 0){
                    if(u.se != v.se){
                        cout << "NO\n";
                        return 0;
                    }
                    continue;
                }

                mn = min(u.se, v.se);
                u.se -= mn;
                v.se -= mn;

                if(u.fi > v.fi){
                    swap(u, v);
                }

                u.se = u.se - v.se;
                pii nx = mp(u.se, v.fi);
                int nwd = __gcd(nx.fi, nx.se);
                nx.fi /= nwd;
                nx.se /= nwd;

                if(x != mp((int)-1e9, (int)-1e9)){
                    if(x.fi * nx.se != nx.fi * x.se){
                        cout << "NO\n";
                        return 0;
                    }
                }else{
                    x = nx;
                }
            }

            if(x != mp((int)-1e9, (int)-1e9)){
                for(auto i : vec){
                    res[i] = (ld)x.fi * val[i].fi / x.se + val[i].se;
                }
                continue;
            }
            
            vi values;
            for(auto i : vec){
                values.pb(val[i].se * (val[i].fi > 0 ? -1 : 1));
            }

            sort(all(values));
            if(sz(vec) % 2 == 1){
                x = {values[sz(vec) / 2], 1};
            }else{
                x = {values[sz(vec) / 2] + values[(sz(vec) + 1) / 2], 2};
            }

            for(auto i : vec){
                res[i] = (ld)x.fi * val[i].fi / x.se + val[i].se;
            }
        }
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Correct 1 ms 2652 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2712 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2652 KB answer = YES
9 Correct 1 ms 2652 KB answer = NO
10 Correct 2 ms 2780 KB answer = YES
11 Correct 2 ms 2648 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 2652 KB answer = YES
16 Correct 1 ms 2640 KB answer = YES
17 Correct 1 ms 2648 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2836 KB answer = YES
21 Correct 1 ms 2648 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 2 ms 2652 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Correct 1 ms 2652 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2712 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2652 KB answer = YES
9 Correct 1 ms 2652 KB answer = NO
10 Correct 2 ms 2780 KB answer = YES
11 Correct 2 ms 2648 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 2652 KB answer = YES
16 Correct 1 ms 2640 KB answer = YES
17 Correct 1 ms 2648 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2836 KB answer = YES
21 Correct 1 ms 2648 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 2 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 2 ms 2612 KB answer = YES
26 Correct 2 ms 2652 KB answer = YES
27 Correct 1 ms 2648 KB answer = YES
28 Correct 1 ms 2820 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 1 ms 2816 KB answer = YES
33 Correct 1 ms 2904 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Correct 1 ms 2652 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2712 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2652 KB answer = YES
9 Correct 1 ms 2652 KB answer = NO
10 Correct 2 ms 2780 KB answer = YES
11 Correct 2 ms 2648 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 2652 KB answer = YES
16 Correct 1 ms 2640 KB answer = YES
17 Correct 1 ms 2648 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2836 KB answer = YES
21 Correct 1 ms 2648 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 2 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 2 ms 2612 KB answer = YES
26 Correct 2 ms 2652 KB answer = YES
27 Correct 1 ms 2648 KB answer = YES
28 Correct 1 ms 2820 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 1 ms 2816 KB answer = YES
33 Correct 1 ms 2904 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 1 ms 2652 KB answer = YES
38 Correct 1 ms 2652 KB answer = YES
39 Correct 1 ms 2652 KB answer = YES
40 Correct 3 ms 2904 KB answer = YES
41 Correct 1 ms 2904 KB answer = NO
42 Correct 2 ms 2908 KB answer = YES
43 Correct 2 ms 2908 KB answer = YES
44 Correct 2 ms 2908 KB answer = YES
45 Correct 2 ms 2908 KB answer = YES
46 Correct 1 ms 2652 KB answer = YES
47 Correct 2 ms 2908 KB answer = YES
48 Correct 2 ms 2908 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Correct 1 ms 2652 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2712 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2652 KB answer = YES
9 Correct 1 ms 2652 KB answer = NO
10 Correct 2 ms 2780 KB answer = YES
11 Correct 2 ms 2648 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 2652 KB answer = YES
16 Correct 1 ms 2640 KB answer = YES
17 Correct 1 ms 2648 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2836 KB answer = YES
21 Correct 1 ms 2648 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 2 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 2 ms 2612 KB answer = YES
26 Correct 2 ms 2652 KB answer = YES
27 Correct 1 ms 2648 KB answer = YES
28 Correct 1 ms 2820 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 1 ms 2816 KB answer = YES
33 Correct 1 ms 2904 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 1 ms 2652 KB answer = YES
38 Correct 1 ms 2652 KB answer = YES
39 Correct 1 ms 2652 KB answer = YES
40 Correct 3 ms 2904 KB answer = YES
41 Correct 1 ms 2904 KB answer = NO
42 Correct 2 ms 2908 KB answer = YES
43 Correct 2 ms 2908 KB answer = YES
44 Correct 2 ms 2908 KB answer = YES
45 Correct 2 ms 2908 KB answer = YES
46 Correct 1 ms 2652 KB answer = YES
47 Correct 2 ms 2908 KB answer = YES
48 Correct 2 ms 2908 KB answer = YES
49 Correct 8 ms 3816 KB answer = YES
50 Correct 7 ms 4188 KB answer = YES
51 Correct 7 ms 4184 KB answer = YES
52 Correct 5 ms 3928 KB answer = NO
53 Correct 2 ms 2904 KB answer = YES
54 Correct 3 ms 2884 KB answer = YES
55 Correct 4 ms 3164 KB answer = YES
56 Correct 7 ms 3676 KB answer = YES
57 Correct 6 ms 3676 KB answer = YES
58 Correct 6 ms 3672 KB answer = YES
59 Correct 6 ms 3420 KB answer = YES
60 Correct 8 ms 3676 KB answer = YES
61 Correct 4 ms 3164 KB answer = YES
62 Correct 42 ms 18964 KB answer = NO
63 Correct 43 ms 14716 KB answer = YES
64 Correct 40 ms 14784 KB answer = NO
65 Correct 43 ms 14804 KB answer = YES
66 Correct 2 ms 2908 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Correct 1 ms 2652 KB answer = NO
5 Correct 1 ms 2652 KB answer = YES
6 Correct 1 ms 2712 KB answer = YES
7 Correct 1 ms 2648 KB answer = YES
8 Correct 1 ms 2652 KB answer = YES
9 Correct 1 ms 2652 KB answer = NO
10 Correct 2 ms 2780 KB answer = YES
11 Correct 2 ms 2648 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 2652 KB answer = YES
16 Correct 1 ms 2640 KB answer = YES
17 Correct 1 ms 2648 KB answer = YES
18 Correct 1 ms 2652 KB answer = YES
19 Correct 1 ms 2652 KB answer = YES
20 Correct 1 ms 2836 KB answer = YES
21 Correct 1 ms 2648 KB answer = YES
22 Correct 1 ms 2652 KB answer = NO
23 Correct 2 ms 2652 KB answer = NO
24 Correct 1 ms 2652 KB answer = YES
25 Correct 2 ms 2612 KB answer = YES
26 Correct 2 ms 2652 KB answer = YES
27 Correct 1 ms 2648 KB answer = YES
28 Correct 1 ms 2820 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 1 ms 2816 KB answer = YES
33 Correct 1 ms 2904 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 1 ms 2652 KB answer = YES
38 Correct 1 ms 2652 KB answer = YES
39 Correct 1 ms 2652 KB answer = YES
40 Correct 3 ms 2904 KB answer = YES
41 Correct 1 ms 2904 KB answer = NO
42 Correct 2 ms 2908 KB answer = YES
43 Correct 2 ms 2908 KB answer = YES
44 Correct 2 ms 2908 KB answer = YES
45 Correct 2 ms 2908 KB answer = YES
46 Correct 1 ms 2652 KB answer = YES
47 Correct 2 ms 2908 KB answer = YES
48 Correct 2 ms 2908 KB answer = YES
49 Correct 8 ms 3816 KB answer = YES
50 Correct 7 ms 4188 KB answer = YES
51 Correct 7 ms 4184 KB answer = YES
52 Correct 5 ms 3928 KB answer = NO
53 Correct 2 ms 2904 KB answer = YES
54 Correct 3 ms 2884 KB answer = YES
55 Correct 4 ms 3164 KB answer = YES
56 Correct 7 ms 3676 KB answer = YES
57 Correct 6 ms 3676 KB answer = YES
58 Correct 6 ms 3672 KB answer = YES
59 Correct 6 ms 3420 KB answer = YES
60 Correct 8 ms 3676 KB answer = YES
61 Correct 4 ms 3164 KB answer = YES
62 Correct 42 ms 18964 KB answer = NO
63 Correct 43 ms 14716 KB answer = YES
64 Correct 40 ms 14784 KB answer = NO
65 Correct 43 ms 14804 KB answer = YES
66 Correct 2 ms 2908 KB answer = YES
67 Correct 62 ms 20852 KB answer = YES
68 Correct 55 ms 20732 KB answer = YES
69 Correct 53 ms 20788 KB answer = YES
70 Correct 96 ms 26716 KB answer = YES
71 Correct 55 ms 20680 KB answer = YES
72 Correct 73 ms 11952 KB answer = YES
73 Correct 59 ms 11976 KB answer = YES
74 Correct 47 ms 13260 KB answer = YES
75 Correct 21 ms 11480 KB answer = NO
76 Correct 8 ms 3928 KB answer = YES
77 Correct 16 ms 5112 KB answer = YES
78 Correct 26 ms 6836 KB answer = YES
79 Correct 61 ms 10704 KB answer = YES
80 Correct 52 ms 13392 KB answer = YES
81 Correct 30 ms 13772 KB answer = NO
82 Correct 65 ms 19912 KB answer = YES
83 Correct 77 ms 20884 KB answer = YES
84 Correct 73 ms 20928 KB answer = YES
85 Correct 64 ms 20928 KB answer = YES
86 Correct 62 ms 20780 KB answer = YES
87 Correct 29 ms 12884 KB answer = NO
88 Correct 67 ms 15156 KB answer = YES
89 Correct 55 ms 10876 KB answer = YES
90 Correct 61 ms 10836 KB answer = YES
91 Correct 62 ms 10892 KB answer = YES
92 Correct 28 ms 7392 KB answer = YES
93 Correct 29 ms 7284 KB answer = YES
94 Correct 37 ms 18160 KB answer = NO
95 Correct 38 ms 9812 KB answer = NO
96 Correct 103 ms 22844 KB answer = YES
97 Correct 26 ms 18376 KB answer = NO