#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const int mod = 1e9 + 7;
const double inf = -1e6;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u -= 1; v -= 1;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<int> comp, was(n);
vector<double> ans(n);
vector<vector<pair<int, int>>> r(n);
function<void(int, int, int, int)> Dfs = [&] (int s, int e, int a, int b) {
was[s] = 1;
r[s].push_back({a, b});
comp.push_back(s);
for (auto u : g[s]) {
if (u.first == e) continue;
if (was[u.first] == 0) {
Dfs(u.first, s, -a, u.second - b);
}
else {
int aa = r[u.first].back().first;
int bb = r[u.first].back().second;
r[s].push_back({-aa, u.second - bb});
}
}
};
for (int i = 0; i < n; i++) {
if (was[i] == 1) continue;
Dfs(i, -1, 1, 0);
int ok = 1;
double pot = inf;
for (int j : comp) {
sort(r[j].begin(), r[j].end());
r[j].erase(unique(r[j].begin(), r[j].end()), r[j].end());
for (int k = 1; k < r[j].size(); k++) {
if (r[j][k].first == r[j][k - 1].first) {
cout << "NO\n";
return 0;
}
double x = (double)(r[j][k].second - r[j][k - 1].second) / (r[j][k - 1].first - r[j][k].first);
if (pot == inf) pot = x;
else if (pot != x) {
cout << "NO\n";
return 0;
}
}
}
if (pot == inf) {
vector<int> v;
for (int j : comp) {
v.push_back(-1 * r[j][0].first * r[j][0].second);
}
sort(v.begin(), v.end());
int ind = comp.size() / 2;
pot = v[ind];
}
for (int j : comp) {
ans[j] = 1.0 * r[j][0].first * pot + r[j][0].second;
}
comp.clear();
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << fixed << showpoint << setprecision(1) << ans[i] << sp;
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:53:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int k = 1; k < r[j].size(); k++) {
| ~~^~~~~~~~~~~~~
Graph.cpp:48:13: warning: unused variable 'ok' [-Wunused-variable]
48 | int ok = 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
340 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
1 ms |
212 KB |
answer = YES |
6 |
Correct |
0 ms |
320 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
1 ms |
320 KB |
answer = YES |
9 |
Correct |
1 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
324 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
0 ms |
212 KB |
answer = YES |
14 |
Correct |
1 ms |
212 KB |
answer = YES |
15 |
Correct |
0 ms |
212 KB |
answer = YES |
16 |
Correct |
1 ms |
212 KB |
answer = YES |
17 |
Correct |
1 ms |
212 KB |
answer = YES |
18 |
Correct |
1 ms |
212 KB |
answer = YES |
19 |
Correct |
1 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
316 KB |
answer = YES |
21 |
Correct |
1 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
340 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
1 ms |
212 KB |
answer = YES |
6 |
Correct |
0 ms |
320 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
1 ms |
320 KB |
answer = YES |
9 |
Correct |
1 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
324 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
0 ms |
212 KB |
answer = YES |
14 |
Correct |
1 ms |
212 KB |
answer = YES |
15 |
Correct |
0 ms |
212 KB |
answer = YES |
16 |
Correct |
1 ms |
212 KB |
answer = YES |
17 |
Correct |
1 ms |
212 KB |
answer = YES |
18 |
Correct |
1 ms |
212 KB |
answer = YES |
19 |
Correct |
1 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
316 KB |
answer = YES |
21 |
Correct |
1 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
24 |
Correct |
1 ms |
320 KB |
answer = YES |
25 |
Correct |
1 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
0 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
1 ms |
340 KB |
answer = NO |
31 |
Correct |
1 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
1 ms |
212 KB |
answer = YES |
34 |
Correct |
1 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
1 ms |
312 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
340 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
1 ms |
212 KB |
answer = YES |
6 |
Correct |
0 ms |
320 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
1 ms |
320 KB |
answer = YES |
9 |
Correct |
1 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
324 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
0 ms |
212 KB |
answer = YES |
14 |
Correct |
1 ms |
212 KB |
answer = YES |
15 |
Correct |
0 ms |
212 KB |
answer = YES |
16 |
Correct |
1 ms |
212 KB |
answer = YES |
17 |
Correct |
1 ms |
212 KB |
answer = YES |
18 |
Correct |
1 ms |
212 KB |
answer = YES |
19 |
Correct |
1 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
316 KB |
answer = YES |
21 |
Correct |
1 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
24 |
Correct |
1 ms |
320 KB |
answer = YES |
25 |
Correct |
1 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
0 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
1 ms |
340 KB |
answer = NO |
31 |
Correct |
1 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
1 ms |
212 KB |
answer = YES |
34 |
Correct |
1 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
1 ms |
312 KB |
answer = YES |
37 |
Correct |
1 ms |
340 KB |
answer = YES |
38 |
Correct |
1 ms |
320 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
468 KB |
answer = YES |
41 |
Correct |
1 ms |
468 KB |
answer = NO |
42 |
Correct |
1 ms |
468 KB |
answer = YES |
43 |
Correct |
1 ms |
468 KB |
answer = YES |
44 |
Correct |
1 ms |
468 KB |
answer = YES |
45 |
Correct |
1 ms |
468 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
468 KB |
answer = YES |
48 |
Correct |
1 ms |
456 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
340 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
1 ms |
212 KB |
answer = YES |
6 |
Correct |
0 ms |
320 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
1 ms |
320 KB |
answer = YES |
9 |
Correct |
1 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
324 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
0 ms |
212 KB |
answer = YES |
14 |
Correct |
1 ms |
212 KB |
answer = YES |
15 |
Correct |
0 ms |
212 KB |
answer = YES |
16 |
Correct |
1 ms |
212 KB |
answer = YES |
17 |
Correct |
1 ms |
212 KB |
answer = YES |
18 |
Correct |
1 ms |
212 KB |
answer = YES |
19 |
Correct |
1 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
316 KB |
answer = YES |
21 |
Correct |
1 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
24 |
Correct |
1 ms |
320 KB |
answer = YES |
25 |
Correct |
1 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
0 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
1 ms |
340 KB |
answer = NO |
31 |
Correct |
1 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
1 ms |
212 KB |
answer = YES |
34 |
Correct |
1 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
1 ms |
312 KB |
answer = YES |
37 |
Correct |
1 ms |
340 KB |
answer = YES |
38 |
Correct |
1 ms |
320 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
468 KB |
answer = YES |
41 |
Correct |
1 ms |
468 KB |
answer = NO |
42 |
Correct |
1 ms |
468 KB |
answer = YES |
43 |
Correct |
1 ms |
468 KB |
answer = YES |
44 |
Correct |
1 ms |
468 KB |
answer = YES |
45 |
Correct |
1 ms |
468 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
468 KB |
answer = YES |
48 |
Correct |
1 ms |
456 KB |
answer = YES |
49 |
Correct |
9 ms |
1996 KB |
answer = YES |
50 |
Correct |
8 ms |
2360 KB |
answer = YES |
51 |
Correct |
9 ms |
2388 KB |
answer = YES |
52 |
Correct |
6 ms |
2260 KB |
answer = NO |
53 |
Correct |
1 ms |
468 KB |
answer = YES |
54 |
Correct |
2 ms |
664 KB |
answer = YES |
55 |
Correct |
6 ms |
1108 KB |
answer = YES |
56 |
Correct |
9 ms |
1876 KB |
answer = YES |
57 |
Correct |
8 ms |
1744 KB |
answer = YES |
58 |
Correct |
8 ms |
1616 KB |
answer = YES |
59 |
Correct |
7 ms |
1620 KB |
answer = YES |
60 |
Correct |
8 ms |
1748 KB |
answer = YES |
61 |
Correct |
4 ms |
1060 KB |
answer = YES |
62 |
Correct |
66 ms |
12624 KB |
answer = NO |
63 |
Correct |
64 ms |
12564 KB |
answer = YES |
64 |
Correct |
86 ms |
12532 KB |
answer = NO |
65 |
Correct |
68 ms |
12644 KB |
answer = YES |
66 |
Correct |
2 ms |
596 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
340 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
1 ms |
212 KB |
answer = YES |
6 |
Correct |
0 ms |
320 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
1 ms |
320 KB |
answer = YES |
9 |
Correct |
1 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
324 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
0 ms |
212 KB |
answer = YES |
14 |
Correct |
1 ms |
212 KB |
answer = YES |
15 |
Correct |
0 ms |
212 KB |
answer = YES |
16 |
Correct |
1 ms |
212 KB |
answer = YES |
17 |
Correct |
1 ms |
212 KB |
answer = YES |
18 |
Correct |
1 ms |
212 KB |
answer = YES |
19 |
Correct |
1 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
316 KB |
answer = YES |
21 |
Correct |
1 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
24 |
Correct |
1 ms |
320 KB |
answer = YES |
25 |
Correct |
1 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
0 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
1 ms |
340 KB |
answer = NO |
31 |
Correct |
1 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
1 ms |
212 KB |
answer = YES |
34 |
Correct |
1 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
1 ms |
312 KB |
answer = YES |
37 |
Correct |
1 ms |
340 KB |
answer = YES |
38 |
Correct |
1 ms |
320 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
468 KB |
answer = YES |
41 |
Correct |
1 ms |
468 KB |
answer = NO |
42 |
Correct |
1 ms |
468 KB |
answer = YES |
43 |
Correct |
1 ms |
468 KB |
answer = YES |
44 |
Correct |
1 ms |
468 KB |
answer = YES |
45 |
Correct |
1 ms |
468 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
468 KB |
answer = YES |
48 |
Correct |
1 ms |
456 KB |
answer = YES |
49 |
Correct |
9 ms |
1996 KB |
answer = YES |
50 |
Correct |
8 ms |
2360 KB |
answer = YES |
51 |
Correct |
9 ms |
2388 KB |
answer = YES |
52 |
Correct |
6 ms |
2260 KB |
answer = NO |
53 |
Correct |
1 ms |
468 KB |
answer = YES |
54 |
Correct |
2 ms |
664 KB |
answer = YES |
55 |
Correct |
6 ms |
1108 KB |
answer = YES |
56 |
Correct |
9 ms |
1876 KB |
answer = YES |
57 |
Correct |
8 ms |
1744 KB |
answer = YES |
58 |
Correct |
8 ms |
1616 KB |
answer = YES |
59 |
Correct |
7 ms |
1620 KB |
answer = YES |
60 |
Correct |
8 ms |
1748 KB |
answer = YES |
61 |
Correct |
4 ms |
1060 KB |
answer = YES |
62 |
Correct |
66 ms |
12624 KB |
answer = NO |
63 |
Correct |
64 ms |
12564 KB |
answer = YES |
64 |
Correct |
86 ms |
12532 KB |
answer = NO |
65 |
Correct |
68 ms |
12644 KB |
answer = YES |
66 |
Correct |
2 ms |
596 KB |
answer = YES |
67 |
Correct |
86 ms |
25868 KB |
answer = YES |
68 |
Correct |
76 ms |
25812 KB |
answer = YES |
69 |
Correct |
71 ms |
25536 KB |
answer = YES |
70 |
Correct |
109 ms |
32288 KB |
answer = YES |
71 |
Correct |
89 ms |
25540 KB |
answer = YES |
72 |
Correct |
95 ms |
15556 KB |
answer = YES |
73 |
Correct |
111 ms |
15172 KB |
answer = YES |
74 |
Correct |
69 ms |
15332 KB |
answer = YES |
75 |
Correct |
32 ms |
14900 KB |
answer = NO |
76 |
Correct |
10 ms |
2200 KB |
answer = YES |
77 |
Correct |
20 ms |
4084 KB |
answer = YES |
78 |
Correct |
34 ms |
6944 KB |
answer = YES |
79 |
Correct |
114 ms |
13376 KB |
answer = YES |
80 |
Correct |
61 ms |
15436 KB |
answer = YES |
81 |
Correct |
57 ms |
19984 KB |
answer = NO |
82 |
Correct |
106 ms |
24636 KB |
answer = YES |
83 |
Correct |
132 ms |
25704 KB |
answer = YES |
84 |
Correct |
111 ms |
25848 KB |
answer = YES |
85 |
Correct |
81 ms |
25796 KB |
answer = YES |
86 |
Correct |
87 ms |
25600 KB |
answer = YES |
87 |
Correct |
54 ms |
15180 KB |
answer = NO |
88 |
Correct |
106 ms |
19080 KB |
answer = YES |
89 |
Correct |
104 ms |
14204 KB |
answer = YES |
90 |
Correct |
88 ms |
14104 KB |
answer = YES |
91 |
Correct |
109 ms |
14156 KB |
answer = YES |
92 |
Correct |
42 ms |
7704 KB |
answer = YES |
93 |
Correct |
39 ms |
7744 KB |
answer = YES |
94 |
Correct |
87 ms |
25156 KB |
answer = NO |
95 |
Correct |
46 ms |
10956 KB |
answer = NO |
96 |
Correct |
185 ms |
26796 KB |
answer = YES |
97 |
Correct |
48 ms |
25064 KB |
answer = NO |