답안 #605035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605035 2022-07-25T12:26:35 Z OttoTheDino Graph (BOI20_graph) C++17
0 / 100
10 ms 14804 KB
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,s,e)                  for (ll i = s; i <= e; ++i)
#define pb                          push_back
#define len(a)                      (ll)a.size()
typedef long long ll;
typedef vector<pair<ll,ll>> vpll;
 
const ll mx = 3e5;

vpll cur, adj[mx+1];
ll coeff[mx+1], ans[mx+1], suc = 1, been[mx+1], c[mx+1];
set<ll> st;

void dfs (ll u, ll p) {
    cur.pb({coeff[u], u});
    for (auto [v,e] : adj[u]) {
        if (e==p) continue;
        if (been[v]) {
            if (been[v]==been[u]) st.insert(been[u]*(c[e]-coeff[u]-coeff[v])/2);
            else if (coeff[v]+coeff[u]!=c[e]) {
                suc = 0;
            }
            continue;
        }
        been[v] = been[u]*-1;
        coeff[v] = c[e]-coeff[u];
        dfs (v,e);
    }
}
 
int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll n, m; cin >> n >> m;
 
    rep (i,1,m) {
        ll u, v; cin >> u >> v;
        adj[u].pb({v,i});
        adj[v].pb({u,i});
        cin >> c[i];
        c[i] *= 2;
    }

    rep (i,1,n) {
        if (been[i]) continue;
        been[i] = 1;
        dfs (i,0);
        ll x = -1;
        if (len(st)>1) {
                assert(0==1);
            suc =0;
            break;
        }
        else if (len(st)==1) x = *st.begin();
        else {
            vpll changes;
            ll best = 5e18;
            rep (j,-100,100) {
                ll cand = 0;
                for (auto [val, u] : cur) cand = abs(val+been[u]*j); 
                if (cand<best) {
                    best = cand;
                    x = j;
                }
            }
        }
        for (auto [val, u] : cur) ans[u] = val+been[u]*x;
        cur.clear();
    }
 
    if (suc) {
        cout << "YES\n";
        rep (i,1,n) cout << ans[i]/2.0 << " \n"[i==n];
    }
    else cout << "NO\n";
 
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 4 ms 7380 KB answer = YES
4 Correct 4 ms 7380 KB answer = NO
5 Correct 4 ms 7380 KB answer = YES
6 Correct 5 ms 7380 KB answer = YES
7 Correct 4 ms 7380 KB answer = YES
8 Correct 3 ms 7380 KB answer = YES
9 Correct 4 ms 7380 KB answer = NO
10 Correct 4 ms 7380 KB answer = YES
11 Correct 4 ms 7380 KB answer = YES
12 Correct 4 ms 7380 KB answer = NO
13 Correct 5 ms 7380 KB answer = YES
14 Correct 4 ms 7380 KB answer = YES
15 Correct 4 ms 7380 KB answer = YES
16 Correct 4 ms 7380 KB answer = YES
17 Correct 4 ms 7380 KB answer = YES
18 Correct 4 ms 7380 KB answer = YES
19 Runtime error 10 ms 14804 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 4 ms 7380 KB answer = YES
4 Correct 4 ms 7380 KB answer = NO
5 Correct 4 ms 7380 KB answer = YES
6 Correct 5 ms 7380 KB answer = YES
7 Correct 4 ms 7380 KB answer = YES
8 Correct 3 ms 7380 KB answer = YES
9 Correct 4 ms 7380 KB answer = NO
10 Correct 4 ms 7380 KB answer = YES
11 Correct 4 ms 7380 KB answer = YES
12 Correct 4 ms 7380 KB answer = NO
13 Correct 5 ms 7380 KB answer = YES
14 Correct 4 ms 7380 KB answer = YES
15 Correct 4 ms 7380 KB answer = YES
16 Correct 4 ms 7380 KB answer = YES
17 Correct 4 ms 7380 KB answer = YES
18 Correct 4 ms 7380 KB answer = YES
19 Runtime error 10 ms 14804 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 4 ms 7380 KB answer = YES
4 Correct 4 ms 7380 KB answer = NO
5 Correct 4 ms 7380 KB answer = YES
6 Correct 5 ms 7380 KB answer = YES
7 Correct 4 ms 7380 KB answer = YES
8 Correct 3 ms 7380 KB answer = YES
9 Correct 4 ms 7380 KB answer = NO
10 Correct 4 ms 7380 KB answer = YES
11 Correct 4 ms 7380 KB answer = YES
12 Correct 4 ms 7380 KB answer = NO
13 Correct 5 ms 7380 KB answer = YES
14 Correct 4 ms 7380 KB answer = YES
15 Correct 4 ms 7380 KB answer = YES
16 Correct 4 ms 7380 KB answer = YES
17 Correct 4 ms 7380 KB answer = YES
18 Correct 4 ms 7380 KB answer = YES
19 Runtime error 10 ms 14804 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 4 ms 7380 KB answer = YES
4 Correct 4 ms 7380 KB answer = NO
5 Correct 4 ms 7380 KB answer = YES
6 Correct 5 ms 7380 KB answer = YES
7 Correct 4 ms 7380 KB answer = YES
8 Correct 3 ms 7380 KB answer = YES
9 Correct 4 ms 7380 KB answer = NO
10 Correct 4 ms 7380 KB answer = YES
11 Correct 4 ms 7380 KB answer = YES
12 Correct 4 ms 7380 KB answer = NO
13 Correct 5 ms 7380 KB answer = YES
14 Correct 4 ms 7380 KB answer = YES
15 Correct 4 ms 7380 KB answer = YES
16 Correct 4 ms 7380 KB answer = YES
17 Correct 4 ms 7380 KB answer = YES
18 Correct 4 ms 7380 KB answer = YES
19 Runtime error 10 ms 14804 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 4 ms 7380 KB answer = YES
4 Correct 4 ms 7380 KB answer = NO
5 Correct 4 ms 7380 KB answer = YES
6 Correct 5 ms 7380 KB answer = YES
7 Correct 4 ms 7380 KB answer = YES
8 Correct 3 ms 7380 KB answer = YES
9 Correct 4 ms 7380 KB answer = NO
10 Correct 4 ms 7380 KB answer = YES
11 Correct 4 ms 7380 KB answer = YES
12 Correct 4 ms 7380 KB answer = NO
13 Correct 5 ms 7380 KB answer = YES
14 Correct 4 ms 7380 KB answer = YES
15 Correct 4 ms 7380 KB answer = YES
16 Correct 4 ms 7380 KB answer = YES
17 Correct 4 ms 7380 KB answer = YES
18 Correct 4 ms 7380 KB answer = YES
19 Runtime error 10 ms 14804 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -