Submission #1095654

# Submission time Handle Problem Language Result Execution time Memory
1095654 2024-10-02T20:08:09 Z Tymond Graph (BOI20_graph) C++17
0 / 100
1 ms 2652 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];
int n, m;
vector<pair<pii, pii>> e;

void dfs(int v){
    vis[v] = 1;
    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 i = 1; i <= n; i++){
    //    if(sz(g[i]) == 0){
   //         cout << "NO\n";
     //       return 0;
    //    }
    //}

    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            val[i] = {1, 0};
            dfs(i);
        }
    }

    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.fi != v.fi){
                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(nx.fi < 0 && nx.se < 0){
            nx.fi *= (-1);
            nx.se *= (-1);
        }

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

    if(x != mp((int)-1e9, (int)-1e9)){
        cout << "YES\n";
        cout << fixed << setprecision(6);
        for(int i = 1; i <= n; i++){
            ld akt = (ld)x.fi * val[i].fi / x.se + val[i].se;
            cout << akt << ' ';
        }
        cout << '\n';
        return 0;
    }
    
    vi values;
    for(int i = 1; i <= n; i++){
        values.pb(val[i].se * (val[i].fi > 0 ? -1 : 1));
       // cout << val[i].fi << ' ' << val[i].se << '\n';
    }

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

    cout << "YES\n";
    cout << fixed << setprecision(6);
    for(int i = 1; i <= n; i++){
        ld akt = (ld)x.fi * val[i].fi / x.se + val[i].se;
        cout << akt << ' ';
    }
    cout << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Incorrect 1 ms 2652 KB Sum of endpoints for edge (2; 1) differs from the expected value 1.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Incorrect 1 ms 2652 KB Sum of endpoints for edge (2; 1) differs from the expected value 1.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Incorrect 1 ms 2652 KB Sum of endpoints for edge (2; 1) differs from the expected value 1.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Incorrect 1 ms 2652 KB Sum of endpoints for edge (2; 1) differs from the expected value 1.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB answer = YES
2 Correct 1 ms 2652 KB answer = YES
3 Correct 1 ms 2652 KB answer = YES
4 Incorrect 1 ms 2652 KB Sum of endpoints for edge (2; 1) differs from the expected value 1.
5 Halted 0 ms 0 KB -