This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define ld long double
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define des first
#define color second
#define par first
#define val second
#define INF 1000000000
lli n,m,a,b,c;
ld xval;
vector<lli> numeros;
vector<pair<lli,lli>> hijos[MAX+2];
pair<lli,ld> estado[MAX+2];
lli visitados[MAX+2];
bool posible;
void solve(lli pos) {
visitados[pos] = 1;
for (auto h : hijos[pos]) {
a = estado[pos].par * (-1);
if (h.color == 1) b = 1 - estado[pos].val;
else b = 2 - estado[pos].val;
if (visitados[h.des] == 0) {
estado[h.des] = {a,b};
if (a == 1) numeros.push_back(-b);
else numeros.push_back(b);
solve(h.des);
}
else {
if (a == estado[h.des].par) {
if (b == estado[h.des].val) continue;
else posible = false;
}
else {
ld x = (h.color - (estado[pos].val + estado[h.des].val))/2;
if (estado[pos].par == -1) x *= -1;
if (xval == INF) xval = x;
if (xval != x) posible = false;
}
}
}
}
void llena(lli pos) {
visitados[pos] = 2;
estado[pos].val += (estado[pos].par * xval);
for (auto h : hijos[pos]) {
if (visitados[h.des] != 2) llena(h.des);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b >> c;
hijos[a].push_back({b,c});
hijos[b].push_back({a,c});
}
posible = true;
rep(i,1,n) {
if (visitados[i] == 0) {
estado[i] = {1,0};
numeros.clear();
numeros.push_back(0);
xval = INF;
solve(i);
if (!posible) break;
if (xval == INF) {
sort(numeros.begin(),numeros.end());
a = numeros.size()/2;
xval = numeros[a];
}
llena(i);
}
}
if (!posible) cout << "NO\n";
else {
cout << "YES\n";
cout << setprecision(1) << fixed;
rep(i,1,n) cout << estado[i].val << ' ';
}
}
# | 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... |