Submission #605052

# Submission time Handle Problem Language Result Execution time Memory
605052 2022-07-25T12:36:19 Z OttoTheDino Graph (BOI20_graph) C++17
0 / 100
5 ms 7380 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 all(a)                      a.begin(), a.end()
#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]!=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) {
            suc =0;
            break;
        }
        else if (len(st)==1) x = *st.begin();
        else {
            vpll changes;
            ll sum = 0, d = 0, best = 5e18;
            for (auto [val, u] : cur) {
                ll imp = -val*been[u];
                sum += been[u]*val;
                d -= been[u];
                changes.pb({imp, u});
            }
            sort(all(changes));
            for (auto [imp, u] : changes) {
                ll cand = sum + d * imp;
                sum -= 2*been[u]*coeff[u];
                d += 2*been[u];
                if (cand<best) {
                    best = cand;
                    x = imp;
                }
            }
        }
        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;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 3 ms 7380 KB answer = YES
4 Correct 5 ms 7380 KB answer = NO
5 Correct 5 ms 7380 KB answer = YES
6 Incorrect 4 ms 7380 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 3 ms 7380 KB answer = YES
4 Correct 5 ms 7380 KB answer = NO
5 Correct 5 ms 7380 KB answer = YES
6 Incorrect 4 ms 7380 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 3 ms 7380 KB answer = YES
4 Correct 5 ms 7380 KB answer = NO
5 Correct 5 ms 7380 KB answer = YES
6 Incorrect 4 ms 7380 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 3 ms 7380 KB answer = YES
4 Correct 5 ms 7380 KB answer = NO
5 Correct 5 ms 7380 KB answer = YES
6 Incorrect 4 ms 7380 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB answer = YES
2 Correct 4 ms 7380 KB answer = YES
3 Correct 3 ms 7380 KB answer = YES
4 Correct 5 ms 7380 KB answer = NO
5 Correct 5 ms 7380 KB answer = YES
6 Incorrect 4 ms 7380 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -