Submission #257530

#TimeUsernameProblemLanguageResultExecution timeMemory
257530VEGAnnGraph (BOI20_graph)C++14
58 / 100
664 ms14584 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define PB push_back #define sz(x) ((int)x.size()) #define i2 array<int,2> using namespace std; typedef long double ld; const int oo = 2e9; const int N = 100100; const int cnst = 80; const int con = 80; queue<int> q; bool was; vector<i2> g[N]; int n, m, col[N], mrk[N], tt; int cost = 0, nm[N]; void BAD(){ cout << "NO"; exit(0); } void dfs(int v, int vl){ if (was) return; if (mrk[v] == tt){ if (col[v] != vl) was = 1; return; } mrk[v] = tt; col[v] = vl; cost += abs(vl); for (i2 u : g[v]) dfs(u[0], u[1] - vl); } mt19937 rnd(chrono::system_clock().now().time_since_epoch().count()); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> m; for (int i = 0; i < m; i++){ int x, y, z; cin >> x >> y >> z; x--; y--; g[x].PB({y, z * 2}); g[y].PB({x, z * 2}); } for (int i = 0; i < n; i++) nm[i] = i; fill(col, col + n, -oo); // shuffle(nm, nm + n, rnd); for (int ite = 0; ite < n; ite++){ // int i = nm[ite]; int i = ite; if (col[i] != -oo) continue; int best = oo, mem = -oo; for (int vl = -cnst; vl <= con; vl++){ was = 0; tt++; cost = 0; while (sz(q)) q.pop(); q.push(i); col[i] = vl; cost = abs(vl); mrk[i] = tt; while (!was && sz(q) && cost < best){ int v = q.front(); q.pop(); for (i2 u : g[v]){ if (mrk[u[0]] == tt){ if (col[u[0]] != u[1] - col[v]){ was = 1; break; } } else { q.push(u[0]); mrk[u[0]] = tt; col[u[0]] = u[1] - col[v]; cost += abs(col[u[0]]); } } } if (!was && best > cost){ best = cost; mem = vl; } } if (best == oo) BAD(); was = 0; tt++; dfs(i, mem); } cout << "YES\n"; for (int i = 0; i < n; i++) cout << fixed << setprecision(10) << ld(col[i]) / 2.0 << " "; 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...