This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: kututay
* created: 20.09.2022 13:13:02
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/Users/kutay/CP/templates/debug.h"
#else
#define debug(...) void(38)
#endif
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int x, y, z; cin >> x >> y >> z, x--, y--;
g[x].emplace_back(y, z * 2);
g[y].emplace_back(x, z * 2);
}
vector<pair<int, int>> k(n);
vector<int> vis(n);
vector<int> ans(n);
for (int i = 0; i < n; i++) {
if (vis[i]) continue;
vector<int> nodes;
int x = 0;
bool flag = false;
function<void(int)> dfs = [&](int node) {
if (vis[node]) return;
vis[node] = 1;
nodes.emplace_back(node);
for (auto [v, w] : g[node]) {
if (!vis[v]) {
k[v].first = -k[node].first;
k[v].second = w - k[node].second;
dfs(v);
} else if (flag) {
if (k[node].first * x + k[node].second + k[v].first * x + k[v].second != w) {
cout << "NO\n";
exit(0);
}
} else {
if (-k[node].first == k[v].first) {
if (w - k[node].second == k[v].second) continue;
else {
cout << "NO\n";
exit(0);
}
}
flag = true;
x = (w - k[node].second - k[v].second) / (k[node].first + k[v].first);
}
}
};
k[i] = {1, 0};
dfs(i);
if (flag == false) {
vector<int> p;
for (int v : nodes) {
p.emplace_back(-k[v].first * k[v].second);
}
sort(p.begin(), p.end());
x = p[(int) p.size() / 2];
}
for (int v : nodes) {
ans[v] = k[v].first * x + k[v].second;
}
}
cout << "YES\n";
for (int x : ans) {
cout << x / 2.0 << " ";
}
cout << '\n';
}
# | 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... |