제출 #258898

#제출 시각아이디문제언어결과실행 시간메모리
258898easruiGraph (BOI20_graph)C++14
0 / 100
3 ms5120 KiB
#include <bits/stdc++.h> #define va first #define vb second #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<pii,int> ppi; typedef pair<int,pii> pip; const int MN = 2e5+5; const int MOD = 1e9+7; const int INF = 1e9; //start at 1:43 int E[MN],dep[MN],cnt[MN],par[MN],odd; double C[MN],sum[MN],val[MN],tmp[MN]; vector<int> G[MN]; bool vis[MN],fail; void dfs(int s) { vis[s] = 1; for(int d:G[s]){ if(odd) 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 = 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) { vis[s] = 1; for(int d:G[s]){ int e = E[d]-s; if(vis[e]){ if(odd&&val[s]+val[e]!=C[d]) fail = 1; } else{ val[e] = C[d]-val[s]; tmp[e] = 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); } dfs(1); fill(vis,vis+N+1,0); if(odd) solve(odd); else{ solve(1); sort(tmp+1,tmp+N+1); double x = -tmp[(N+1)/2]; for(int i=1; i<=N; i++){ if(dep[i]%2) val[i] -= x; else val[i] += 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...