#include <bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10,
MAX = 1'000'000'000;
int n, m;
vector<pair<int, int>> ad[N];
int a[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v, w; cin >> u >> v >> w;
w *= 10;
ad[u].push_back({v, w});
ad[v].push_back({u, w});
}
auto cal = [&](int x) {
memset(a, -1, sizeof a);
a[1] = x;
queue<int> q({1});
int ret = 0;
while (q.size()) {
auto u = q.front(); q.pop();
ret += abs(a[u]);
for (const auto& [v, w] : ad[u]) {
if (a[v] == -1) {
a[v] = w - a[u];
q.push(v);
}
if (w - a[u] != a[v]) return MAX;
}
}
return ret;
};
int st = -1;
int answer = MAX;
for (int x = -10; x <= 30; x += 5) {
int value = cal(x);
if (answer > value) {
answer = value;
st = x;
}
}
if (st == -1) { cout << "NO" << "\n"; return 0; }
cal(st);
cout << "YES" << "\n";
for (int i = 1; i <= n; ++i) {
if (a[i] < 0) cout << '-' << a[i] / 10 << "." << abs(a[i]) % 10 << " ";
else cout << a[i] / 10 << "." << abs(a[i]) % 10 << " ";
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
answer = YES |
2 |
Correct |
1 ms |
3164 KB |
answer = YES |
3 |
Correct |
1 ms |
3164 KB |
answer = YES |
4 |
Correct |
1 ms |
3164 KB |
answer = NO |
5 |
Incorrect |
1 ms |
3164 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
answer = YES |
2 |
Correct |
1 ms |
3164 KB |
answer = YES |
3 |
Correct |
1 ms |
3164 KB |
answer = YES |
4 |
Correct |
1 ms |
3164 KB |
answer = NO |
5 |
Incorrect |
1 ms |
3164 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
answer = YES |
2 |
Correct |
1 ms |
3164 KB |
answer = YES |
3 |
Correct |
1 ms |
3164 KB |
answer = YES |
4 |
Correct |
1 ms |
3164 KB |
answer = NO |
5 |
Incorrect |
1 ms |
3164 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
answer = YES |
2 |
Correct |
1 ms |
3164 KB |
answer = YES |
3 |
Correct |
1 ms |
3164 KB |
answer = YES |
4 |
Correct |
1 ms |
3164 KB |
answer = NO |
5 |
Incorrect |
1 ms |
3164 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
answer = YES |
2 |
Correct |
1 ms |
3164 KB |
answer = YES |
3 |
Correct |
1 ms |
3164 KB |
answer = YES |
4 |
Correct |
1 ms |
3164 KB |
answer = NO |
5 |
Incorrect |
1 ms |
3164 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |