Submission #1170954

#TimeUsernameProblemLanguageResultExecution timeMemory
1170954alir3za_zar3Graph (BOI20_graph)C++20
0 / 100
16 ms33096 KiB
// Alir3za.Zar3 -> Shiraz , Iran #include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ld long double const int mxN = 2e5+7; const ld vaL = 1e9+7 , inF = 2e18+7; int n,m,typ; ld val[10][mxN]; bool vis[mxN]; vector<pair<int,ld>> e[mxN]; vector<int> vr; void dfs (int v , int p , ld q) { vr.push_back(v); val[typ][v] = q; vis[v] = true; for (auto [to,w] : e[v]) { if (!vis[to]) dfs(to , v , w-q); else { if (val[typ][to] != w-q) val[typ][to] = inF; } } } signed main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=0; i<m; i++) { int u , v; ld w; cin >> u >> v >> w; e[u].push_back({v,w}); e[v].push_back({u,w}); } int out = 10 , update = inF; for (int t=0; t<9; t++) fill_n(val[t] , mxN , vaL); for (int st=1; st<=n; st++) { if (vis[st]) continue; typ = 0; for (ld q=-2.0; q<=2; q+=0.5 , typ++) { dfs (st , st , q); for (auto v : vr) vis[v] = false; } typ = 9; dfs(st , st , 0); } for (int t=0; t<9; t++) { ld S = 0; bool mrk = 1; for (int i=1; i<=n; i++) { if (val[t][i] == inF) { mrk = false; break; } S += (val[t][i]<0 ? -1:1) * val[t][i]; } if (mrk and S < update) update = S , out = t; } if (out == 10) cout << "NO\n"; else { cout << "YES\n"; cout.precision(1); for (int i=1; i<=n; i++) cout << fixed << val[out][i] << ' '; } }

Compilation message (stderr)

Graph.cpp: In function 'int main()':
Graph.cpp:43:29: warning: overflow in conversion from 'long double' to 'int' changes value from '2.0e+18l' to '2147483647' [-Woverflow]
   43 |     int out = 10 , update = inF;
      |                             ^~~
#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...