/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
const LL mod = 1e9 + 7, inf = 1e9;
vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };
void solve() {
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> gp(n);
for(int i = 0; i < m; ++i){
int u, v, w; cin >> u >> v >> w; w *= 2;
gp[--u].push_back({--v, w});
gp[v].push_back({u, w});
}
vector<int> ans(n, inf), val(n), comp;
vector<bool> vis;
int sm = 0;
function<void(int)> dfs = [&](int u){
vis[u] = 1;
if(sm != inf) {
sm += abs(val[u]);
}
for(pair<int, int> &v : gp[u]) {
if(!vis[v.first]) {
val[v.first] = v.second - val[u];
dfs(v.first);
}
else if(val[u] + val[v.first] != v.second) {
sm = inf;
}
}
};
vector<int> res(n, 1e9);
vector<int> start(n, -1e9);
for(int a = -60; a <= 60; ++a){
vis = vector<bool> (n);
val = vector<int> (n);
for(int i = 0; i < n; ++i) {
if(vis[i]) {
continue;
}
sm = 0;
val[i] = a;
dfs(i);
if(sm < ans[i]) {
start[i] = a;
ans[i] = sm;
}
}
}
function<void(int)> res_dfs = [&](int u){
res[u] = val[u];
vis[u] = 1;
for(pair<int, int> &v : gp[u]){
if(!vis[v.first]) {
val[v.first] = v.second - val[u];
res_dfs(v.first);
}
else if(val[u] + val[v.first] != v.second) {
cout << "NO\n";
return;
}
}
};
vis = vector<bool> (n);
val = vector<int> (n);
for(int i = 0; i < n; ++i){
if(start[i] == -1e9) {
continue;
}
val[i] = start[i];
res_dfs(i);
}
cout << "YES\n";
for(int i = 0; i < n; ++i) {
cout << res[i] / 2.0 << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t; while(t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (1; 2) differs from the expected value 2. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (1; 2) differs from the expected value 2. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (1; 2) differs from the expected value 2. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (1; 2) differs from the expected value 2. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (1; 2) differs from the expected value 2. |
5 |
Halted |
0 ms |
0 KB |
- |