Submission #257538

#TimeUsernameProblemLanguageResultExecution timeMemory
257538VEGAnnGraph (BOI20_graph)C++14
0 / 100
2 ms2688 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 = 100; const int con = 50; 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); } 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(); tt++; while (sz(q)) q.pop(); int vl = mem; q.push(i); col[i] = vl; mrk[i] = tt; while (sz(q)){ int v = q.front(); q.pop(); for (i2 u : g[v]){ if (!mrk[u[0]] == tt) { q.push(u[0]); mrk[u[0]] = tt; col[u[0]] = u[1] - col[v]; } } } } cout << "YES\n"; for (int i = 0; i < n; i++) cout << fixed << setprecision(10) << ld(col[i]) / 2.0 << " "; return 0; }

Compilation message (stderr)

Graph.cpp: In function 'int main()':
Graph.cpp:115:32: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
                 if (!mrk[u[0]] == tt) {
                                ^~
Graph.cpp:115:21: note: add parentheses around left hand side expression to silence this warning
                 if (!mrk[u[0]] == tt) {
                     ^~~~~~~~~~
                     (         )
#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...