#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
const int N = 1e5 + 5;
int n, m;
double ans[N];
pair<int, int> val[N], x;
bool mark[N], markx, fail;
vector<pair<int, int>> adj[N];
vector<int> a, now;
void dfs(int v) {
if (fail) return;
mark[v] = true;
now.push_back(v);
for (auto [to, w] : adj[v]) {
if (mark[to]) {
if (val[v].nd != val[to].nd) {
if (val[v].st + val[to].st != w) {fail = true; return;}
}
else {
if (markx) {
if (x.nd*(val[v].st+val[to].st) + x.st*(val[v].nd+val[to].nd) != x.nd*w) {
fail = true; return;
}
}
else if (val[v].nd == val[to].nd) {
x = {w-(val[v].st+val[to].st), val[v].nd+val[to].nd};
markx = true;
}
}
}
else {
val[to] = {w-val[v].st, -val[v].nd};
dfs(to);
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
scanf(" %d %d", &n, &m);
while (m--) {
int u, v, w;
scanf(" %d %d %d", &u, &v, &w);
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
for (int i=1; i<=n; i++) if (!mark[i]) {
markx = false;
now.clear();
val[i] = {0, 1};
dfs(i);
if (fail) {printf("NO"); return 0;}
if (!markx) {
a.clear();
for (auto i : now) a.push_back(-val[i].nd*val[i].st);
sort(a.begin(), a.end());
x = {a[a.size()/2], 1};
}
for (auto i : now) ans[i] = (double)(x.st*val[i].nd+x.nd*val[i].st) / (double)x.nd;
}
printf("YES\n");
for (int i=1; i<=n; i++) printf("%lf ", ans[i]);
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf(" %d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~
Graph.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf(" %d %d %d", &u, &v, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2656 KB |
answer = YES |
11 |
Correct |
1 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2632 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
1 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2656 KB |
answer = YES |
11 |
Correct |
1 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2632 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
1 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2644 KB |
answer = YES |
29 |
Correct |
1 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
1 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
1 ms |
2680 KB |
answer = YES |
36 |
Correct |
2 ms |
2676 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2656 KB |
answer = YES |
11 |
Correct |
1 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2632 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
1 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2644 KB |
answer = YES |
29 |
Correct |
1 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
1 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
1 ms |
2680 KB |
answer = YES |
36 |
Correct |
2 ms |
2676 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2648 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2772 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
3 ms |
2644 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
3 ms |
2688 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2656 KB |
answer = YES |
11 |
Correct |
1 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2632 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
1 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2644 KB |
answer = YES |
29 |
Correct |
1 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
1 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
1 ms |
2680 KB |
answer = YES |
36 |
Correct |
2 ms |
2676 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2648 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2772 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
3 ms |
2644 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
3 ms |
2688 KB |
answer = YES |
49 |
Correct |
8 ms |
3464 KB |
answer = YES |
50 |
Correct |
9 ms |
3712 KB |
answer = YES |
51 |
Correct |
9 ms |
3796 KB |
answer = YES |
52 |
Correct |
5 ms |
3156 KB |
answer = NO |
53 |
Correct |
3 ms |
2688 KB |
answer = YES |
54 |
Correct |
3 ms |
2820 KB |
answer = YES |
55 |
Correct |
6 ms |
3124 KB |
answer = YES |
56 |
Correct |
8 ms |
3540 KB |
answer = YES |
57 |
Correct |
9 ms |
3540 KB |
answer = YES |
58 |
Correct |
8 ms |
3328 KB |
answer = YES |
59 |
Correct |
8 ms |
3412 KB |
answer = YES |
60 |
Correct |
9 ms |
3412 KB |
answer = YES |
61 |
Correct |
5 ms |
3028 KB |
answer = YES |
62 |
Correct |
65 ms |
9420 KB |
answer = NO |
63 |
Correct |
74 ms |
10068 KB |
answer = YES |
64 |
Correct |
71 ms |
10068 KB |
answer = NO |
65 |
Correct |
70 ms |
10120 KB |
answer = YES |
66 |
Correct |
3 ms |
2840 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2656 KB |
answer = YES |
11 |
Correct |
1 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2632 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
1 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2644 KB |
answer = YES |
29 |
Correct |
1 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
1 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
1 ms |
2680 KB |
answer = YES |
36 |
Correct |
2 ms |
2676 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2648 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2772 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
3 ms |
2644 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
3 ms |
2688 KB |
answer = YES |
49 |
Correct |
8 ms |
3464 KB |
answer = YES |
50 |
Correct |
9 ms |
3712 KB |
answer = YES |
51 |
Correct |
9 ms |
3796 KB |
answer = YES |
52 |
Correct |
5 ms |
3156 KB |
answer = NO |
53 |
Correct |
3 ms |
2688 KB |
answer = YES |
54 |
Correct |
3 ms |
2820 KB |
answer = YES |
55 |
Correct |
6 ms |
3124 KB |
answer = YES |
56 |
Correct |
8 ms |
3540 KB |
answer = YES |
57 |
Correct |
9 ms |
3540 KB |
answer = YES |
58 |
Correct |
8 ms |
3328 KB |
answer = YES |
59 |
Correct |
8 ms |
3412 KB |
answer = YES |
60 |
Correct |
9 ms |
3412 KB |
answer = YES |
61 |
Correct |
5 ms |
3028 KB |
answer = YES |
62 |
Correct |
65 ms |
9420 KB |
answer = NO |
63 |
Correct |
74 ms |
10068 KB |
answer = YES |
64 |
Correct |
71 ms |
10068 KB |
answer = NO |
65 |
Correct |
70 ms |
10120 KB |
answer = YES |
66 |
Correct |
3 ms |
2840 KB |
answer = YES |
67 |
Correct |
75 ms |
16960 KB |
answer = YES |
68 |
Correct |
73 ms |
16760 KB |
answer = YES |
69 |
Correct |
79 ms |
16396 KB |
answer = YES |
70 |
Correct |
102 ms |
20264 KB |
answer = YES |
71 |
Correct |
69 ms |
16436 KB |
answer = YES |
72 |
Correct |
78 ms |
11148 KB |
answer = YES |
73 |
Correct |
75 ms |
10948 KB |
answer = YES |
74 |
Correct |
51 ms |
10876 KB |
answer = YES |
75 |
Correct |
28 ms |
7976 KB |
answer = NO |
76 |
Correct |
10 ms |
3716 KB |
answer = YES |
77 |
Correct |
18 ms |
4844 KB |
answer = YES |
78 |
Correct |
32 ms |
6404 KB |
answer = YES |
79 |
Correct |
69 ms |
9956 KB |
answer = YES |
80 |
Correct |
55 ms |
11116 KB |
answer = YES |
81 |
Correct |
50 ms |
11652 KB |
answer = NO |
82 |
Correct |
80 ms |
16056 KB |
answer = YES |
83 |
Correct |
95 ms |
16648 KB |
answer = YES |
84 |
Correct |
96 ms |
16908 KB |
answer = YES |
85 |
Correct |
75 ms |
16956 KB |
answer = YES |
86 |
Correct |
73 ms |
16576 KB |
answer = YES |
87 |
Correct |
50 ms |
10792 KB |
answer = NO |
88 |
Correct |
97 ms |
12712 KB |
answer = YES |
89 |
Correct |
75 ms |
9580 KB |
answer = YES |
90 |
Correct |
77 ms |
9592 KB |
answer = YES |
91 |
Correct |
74 ms |
9636 KB |
answer = YES |
92 |
Correct |
36 ms |
6732 KB |
answer = YES |
93 |
Correct |
35 ms |
6768 KB |
answer = YES |
94 |
Correct |
56 ms |
14744 KB |
answer = NO |
95 |
Correct |
46 ms |
8800 KB |
answer = NO |
96 |
Correct |
142 ms |
17800 KB |
answer = YES |
97 |
Correct |
40 ms |
14784 KB |
answer = NO |