Submission #1030520

#TimeUsernameProblemLanguageResultExecution timeMemory
103052012345678Graph (BOI20_graph)C++17
0 / 100
2 ms2828 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, m, u, v, w, a[nx], b[nx], f, vs[nx]; double res[nx]; vector<pair<int, int>> d[nx]; vector<int> comp; set<double> s; void dfs(int u, int p) { vs[u]=1; comp.push_back(u); for (auto [v, w]:d[u]) { if (v==p) continue; if (vs[v]) { int sma=a[u]+a[v], smb=b[u]+b[v]; if (sma==0&&b[u]+b[v]==w) continue; else if (sma==0&&b[u]+b[v]!=w) { f=1; break; } s.insert(((double)(w-smb))/((double)sma)); } else { a[v]=-a[u]; b[v]=w-b[u]; dfs(v, u); } } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w}); for (int i=1; i<=n; i++) { if (!vs[i]) { comp.clear(); s.clear(); a[i]=1; dfs(i, i); if (s.size()>1) f=1; else if (s.size()==1) { double vl=*s.begin(); for (auto x:comp) res[x]=a[x]*vl+b[x]; } else { vector<double> v; for (auto x:comp) if (a[x]!=0) v.push_back((double)(-b[x])/(double)a[x]); sort(v.begin(), v.end()); pair<double, double> mn={1e18, 0}; for (auto k:v) { double tmp=0; for (auto x:comp) tmp+=abs((double)a[x]*k+(double)b[x]); mn=min(mn, {tmp, k}); } for (auto x:comp) res[x]=mn.second*a[x]+b[x]; } } } if (f) return cout<<"NO\n", 0; cout<<"YES\n"; for (int i=1; i<=n; i++) cout<<setprecision(8)<<res[i]<<' '; }
#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...