답안 #580087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580087 2022-06-20T14:49:19 Z jiahng Graph (BOI20_graph) C++14
100 / 100
180 ms 21376 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 100010
#define INF (ll)1e9+10
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N,M,a,b,c;
bool vis[maxn];
vpi adj[maxn];

ld value;
int status = 0; // status is 0 if not set, 1 if fixed and -1 if no solution
pi val[maxn];
vi v;
ld ans[maxn];
void dfs(int x){
    if (status == -1) return;
    vis[x] = 1;
    v.pb(x);
    aFOR(i,adj[x]){
        if (vis[i.f]){
           pi cur = val[x];
           cur.f += val[i.f].f;
           cur.s += val[i.f].s;
           if (cur.f == 0){
               if (cur.s != i.s){
                  status = -1; return;
               }
           }else{
               ld newvalue = (ld(i.s) - ld(cur.s)) / ld(cur.f);
               if (status == 1 && value != newvalue){
                   status = -1; return;
               }
               value = newvalue;
               status = 1;
           }
        }else{
            val[i.f] = pi(-val[x].f, i.s - val[x].s);
            dfs(i.f);
        }
    }
}
int32_t main(){
    fast;
    cin >> N >> M;
    FOR(i,1,M){
        cin >> a >> b >> c;
        adj[a].pb(pi(b, c)); adj[b].pb(pi(a,c));
    }
    FOR(i,1,N) if (!vis[i]){
        val[i] = pi(1,0);
        status = 0;
        v.clear();
        dfs(i);
        if (status == -1){
            cout << "NO"; return 0;
        }else if (status == 0){
            aFOR(j,v) aFOR(k,adj[j]) assert(val[j].f + val[k.f].f == 0);
            vi v2;
            aFOR(j,v){
                if (val[j].f == -1) v2.pb(val[j].s);
                else v2.pb(-val[j].s);
            }
            sort(all(v2));
            value = v2[v2.size()/2];
        }
        
        aFOR(j,v) ans[j] = (ld)val[j].f * value + (ld)val[j].s;
        aFOR(j,v) aFOR(k,adj[j]) if (ans[j] + ans[k.f] != k.s){
            cout << "NO"; return 0;
        }
    }
    cout << "YES\n";
    FOR(i,1,N) cout << setprecision(10) << ans[i] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 1 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 1 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2644 KB answer = YES
44 Correct 3 ms 2668 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 1 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2644 KB answer = YES
44 Correct 3 ms 2668 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
49 Correct 10 ms 3460 KB answer = YES
50 Correct 10 ms 3796 KB answer = YES
51 Correct 11 ms 3844 KB answer = YES
52 Correct 5 ms 3028 KB answer = NO
53 Correct 2 ms 2772 KB answer = YES
54 Correct 4 ms 2900 KB answer = YES
55 Correct 5 ms 3144 KB answer = YES
56 Correct 10 ms 3460 KB answer = YES
57 Correct 10 ms 3380 KB answer = YES
58 Correct 9 ms 3412 KB answer = YES
59 Correct 9 ms 3284 KB answer = YES
60 Correct 11 ms 3540 KB answer = YES
61 Correct 6 ms 3104 KB answer = YES
62 Correct 46 ms 7628 KB answer = NO
63 Correct 54 ms 8116 KB answer = YES
64 Correct 50 ms 8100 KB answer = NO
65 Correct 73 ms 10424 KB answer = YES
66 Correct 4 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 2 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 2 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 2 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 2 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 1 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 1 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 2 ms 2772 KB answer = YES
43 Correct 2 ms 2644 KB answer = YES
44 Correct 3 ms 2668 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 2 ms 2772 KB answer = YES
48 Correct 2 ms 2772 KB answer = YES
49 Correct 10 ms 3460 KB answer = YES
50 Correct 10 ms 3796 KB answer = YES
51 Correct 11 ms 3844 KB answer = YES
52 Correct 5 ms 3028 KB answer = NO
53 Correct 2 ms 2772 KB answer = YES
54 Correct 4 ms 2900 KB answer = YES
55 Correct 5 ms 3144 KB answer = YES
56 Correct 10 ms 3460 KB answer = YES
57 Correct 10 ms 3380 KB answer = YES
58 Correct 9 ms 3412 KB answer = YES
59 Correct 9 ms 3284 KB answer = YES
60 Correct 11 ms 3540 KB answer = YES
61 Correct 6 ms 3104 KB answer = YES
62 Correct 46 ms 7628 KB answer = NO
63 Correct 54 ms 8116 KB answer = YES
64 Correct 50 ms 8100 KB answer = NO
65 Correct 73 ms 10424 KB answer = YES
66 Correct 4 ms 2772 KB answer = YES
67 Correct 81 ms 17076 KB answer = YES
68 Correct 78 ms 16884 KB answer = YES
69 Correct 81 ms 16888 KB answer = YES
70 Correct 108 ms 21376 KB answer = YES
71 Correct 83 ms 17084 KB answer = YES
72 Correct 124 ms 11344 KB answer = YES
73 Correct 103 ms 11336 KB answer = YES
74 Correct 56 ms 11136 KB answer = YES
75 Correct 27 ms 8056 KB answer = NO
76 Correct 13 ms 3828 KB answer = YES
77 Correct 24 ms 4908 KB answer = YES
78 Correct 46 ms 6508 KB answer = YES
79 Correct 90 ms 10032 KB answer = YES
80 Correct 58 ms 11148 KB answer = YES
81 Correct 42 ms 12116 KB answer = NO
82 Correct 98 ms 16628 KB answer = YES
83 Correct 122 ms 17064 KB answer = YES
84 Correct 110 ms 17088 KB answer = YES
85 Correct 86 ms 17044 KB answer = YES
86 Correct 80 ms 16984 KB answer = YES
87 Correct 42 ms 11712 KB answer = NO
88 Correct 103 ms 13052 KB answer = YES
89 Correct 87 ms 9812 KB answer = YES
90 Correct 119 ms 9808 KB answer = YES
91 Correct 102 ms 9848 KB answer = YES
92 Correct 46 ms 7108 KB answer = YES
93 Correct 44 ms 6988 KB answer = YES
94 Correct 57 ms 15192 KB answer = NO
95 Correct 43 ms 9528 KB answer = NO
96 Correct 180 ms 19168 KB answer = YES
97 Correct 36 ms 15096 KB answer = NO