#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
double EPS = 1e-8;
vector<pair<int, bool>> adj[100000];
int n, m, c[100000];
double x = 1e18, ans[100000];
bool s[100000], vis[100000], ok = true;
vector<int> comp;
void dfs(int u){
vis[u] = 1; comp.push_back(u);
for(auto &[v, w] : g[u]){
if(!vis[v]){
s[v] = !s[u];
c[v] = (2 - (int)w) - c[u];
dfs(v);
}else if(s[u] == s[v]) x = ((2 - (int)w) - c[u] - c[v]) / (s[u] ? -2.0 : 2.0);
}
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
while(m--){
int u, v, w; cin >> u >> v >> w;
--u, --v;
adj[u].emplace_back(v, w & 1);
adj[v].emplace_back(u, w & 1);
}
for(int z = 0; z < n && ok; z++){
if(vis[z]) continue;
comp.clear(); x = 1e18; dfs(z);
if(x > 1e17){
vector<int> v;
for(int i : comp) v.push_back(s[i] ? c[i] : -c[i]);
sort(v.begin(), v.end());
x = v[(int)v.size() / 2];
}
for(int i : comp) ans[i] = (c[i] + (s[i] ? -x : x));
}
for(int u = 0; u < n; u++) for(auto &[v, w] : adj[u]) ok &&= abs((2 - (int)w) - ans[u] - ans[v]) < EPS;
if(!ok) cout << "NO\n";
else{
cout << "YES\n";
cout << setprecision(1) << fixed;
for(int i = 0; i < n; i++) cout << r[i] << ' ';
}
}
Compilation message
Graph.cpp: In function 'void dfs(long long int)':
Graph.cpp:17:21: error: 'g' was not declared in this scope
17 | for(auto &[v, w] : g[u]){
| ^
Graph.cpp: In function 'int main()':
Graph.cpp:46:61: error: expected primary-expression before '=' token
46 | for(int u = 0; u < n; u++) for(auto &[v, w] : adj[u]) ok &&= abs((2 - (int)w) - ans[u] - ans[v]) < EPS;
| ^
Graph.cpp:51:38: error: 'r' was not declared in this scope
51 | for(int i = 0; i < n; i++) cout << r[i] << ' ';
| ^