#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=1e5+5;
vector<pii>g[mxn];
int vis[mxn]{0};
vector<pii>var(mxn);
vector<int>cur;
int ans[mxn];bool ch=0;
int x=0;
//-> a+/-x (a,+/-)
void dfs(int u,int val,int sg){
var[u]=make_pair(val,sg);
vis[u]=1;cur.pb(u);
for(auto [v,w]:g[u]){
if(!vis[v])dfs(v,w-val,sg^1);
if(!ch&&var[u].s==var[v].s){
ch=1;
double t=w-(var[u].f+var[v].f);
if(var[u].s==0)x=t;
else x=-t;
}
}
}
void cal(int u){
ans[u] = 2*var[u].f;
if(var[u].s==0)ans[u]+=x;
else ans[u]-=x;
vis[u]=2;
for(auto [v,w]:g[u]){
if(vis[v]!=2)cal(v);
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b,c;cin>>a>>b>>c;
g[a].pb({b,c});
g[b].pb({a,c});
}
for(int i=1;i<=n;i++){
if(vis[i])continue;
dfs(i,0,0);
if(ch==1){
cal(i);
ch=0;cur.clear();x=0;
continue;
}vector<int>val;
for(auto it : cur){
if(var[it].s==0)val.pb(-var[it].f);
else val.pb(var[it].f);
}sort(all(val));int sz=val.size();
x=2*val[sz/2];
cal(i);
ch=0;cur.clear();x=0;
}bool ok=1;
for(int i=1;i<=n;i++){
for(auto [v,w] : g[i])if(ans[i]+ans[v]!=2*w)ok=0;
}
if(!ok){cout<<"NO";return 0;}cout<<"YES\n";
for(int i=1;i<=n;i++)cout<<ans[i]/2.0<<' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |