Submission #258907

#TimeUsernameProblemLanguageResultExecution timeMemory
258907easruiGraph (BOI20_graph)C++14
0 / 100
5 ms5120 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() const int MN = 2e5+5; //start at 1:43 int E[MN],dep[MN],cnt[MN],par[MN],odd[MN],cur; double C[MN],sum[MN],val[MN]; vector<int> G[MN],group; vector<double> tmp; bool vis[MN],fail; void dfs(int s) { vis[s] = 1; for(int d:G[s]){ if(odd[cur]) break; int e = E[d]-s; if(vis[e]){ if(dep[e]<dep[s]) continue; if((dep[e]-dep[s])%2){ if( (cnt[e]-cnt[par[s]]) - (cnt[par[e]]-cnt[s]) != C[d]-1) fail = 1; } else{ odd[cur] = s; val[s] = (-sum[e]+sum[s]+sum[par[e]]-sum[par[s]]+C[d])/2.0; } } else{ par[e] = s; dep[e] = dep[s]+1; cnt[e] = cnt[par[s]]; if(C[d]==2) cnt[e]++; sum[e] = sum[par[s]]+C[d]; dfs(e); } } } void solve(int s) { group.push_back(s); vis[s] = 1; for(int d:G[s]){ int e = E[d]-s; if(vis[e]){ if(odd[cur]&&val[s]+val[e]!=C[d]) fail = 1; } else{ val[e] = C[d]-val[s]; tmp.push_back(dep[e]%2 ? -val[e] : val[e]); solve(e); } } } int N,M; int main() { ios_base::sync_with_stdio(0),cin.tie(0); cin >> N >> M; for(int i=0; i<M; i++){ int a,b; cin >> a >> b >> C[i]; E[i] = a+b; G[a].push_back(i); G[b].push_back(i); } for(int i=1; i<=N; i++){ if(vis[i]) continue; cur = i; dfs(i); if(!odd[i]) odd[i] = -1; } fill(vis,vis+N+1,0); for(int i=1; i<=N; i++){ if(!odd[i]) continue; cur = i; if(odd[i]>0) solve(odd[i]); else{ group.clear(); tmp.clear(); solve(i); sort(all(group)); double x = -tmp[(group.size()+1)/2]; for(int s:group){ if(dep[s]%2) val[s] -= x; else val[s] += x; } } } fixed(cout); cout.precision(6); if(fail) cout << "NO"; else{ cout << "YES\n"; for(int i=1; i<=N; i++) cout << val[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...