Submission #1095660

#TimeUsernameProblemLanguageResultExecution timeMemory
1095660TymondGraph (BOI20_graph)C++17
100 / 100
103 ms26716 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...