#include <bits/stdc++.h>
using namespace std;
using ld = long double;
int inf = 1e9 + 123;
int n, m;
vector<pair<int,int>> g[100005];
vector<vector<int>> cc;
vector<int> cur_cc;
vector<ld> vls;
bool viz[100005];
ld coef[100005], ofs[100005];
ld ans[100005];
bool possible = true;
ld trb_x = inf;
void dfs(int nod)
{
viz[nod] = true;
cur_cc.push_back(nod);
for (auto vecin : g[nod])
{
if (!viz[vecin.first])
{
coef[vecin.first] = -coef[nod];
ofs[vecin.first] = vecin.second - ofs[nod];
dfs(vecin.first);
}
else
{
ld ncf = -coef[nod];
ld nofs = vecin.second - ofs[nod];
if (ncf == coef[vecin.first] and nofs != ofs[vecin.first])
possible = false;
else if (ncf != coef[vecin.first])
{
//cout << nod << ' ' << vecin.first << ' ' << ncf << ' ' << nofs << ' ' << coef[vecin.first] << ' ' << ofs[vecin.first] << endl;
ld ex_x = trb_x;
if (ncf == -1)
trb_x = (ld)(nofs - ofs[vecin.first]) / 2.0d;
else
trb_x = (ld)(ofs[vecin.first] - nofs) / 2.0d;
//cout << ex_x << ' ' << trb_x << endl;
if (ex_x != trb_x and ex_x != inf)
possible = false;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y, z;
cin >> x >> y >> z;
g[x].push_back({y, z});
g[y].push_back({x, z});
}
for (int i = 1; i <= n; i++)
{
if (!viz[i])
{
trb_x = inf;
cur_cc.clear();
coef[i] = 1, ofs[i] = 0;
dfs(i);
cc.push_back(cur_cc);
vls.push_back(trb_x);
}
}
if (!possible)
{
cout << "NO";
return 0;
}
for (int i = 0; i < cc.size(); i++)
{
if (vls[i] != inf)
{
for (auto it : cc[i])
ans[it] = coef[it] * vls[i] + ofs[it];
}
else
{
vector<ld> pct;
for (auto it : cc[i])
pct.push_back(-ofs[it] / coef[it]);
sort(pct.begin(), pct.end());
int pz = pct.size() / 2;
vls[i] = pct[pz];
for (auto it : cc[i])
ans[it] = coef[it] * vls[i] + ofs[it];
}
}
cout << "YES\n";
cout << setprecision(10) << fixed;
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
return 0;
}
/*
3 3
1 2 1
2 3 2
1 3 2
*/
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < cc.size(); i++)
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2808 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2904 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2648 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2648 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2808 KB |
answer = YES |
17 |
Correct |
2 ms |
2652 KB |
answer = YES |
18 |
Correct |
2 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
2 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2808 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2904 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2648 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2648 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2808 KB |
answer = YES |
17 |
Correct |
2 ms |
2652 KB |
answer = YES |
18 |
Correct |
2 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
2 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
2 ms |
2652 KB |
answer = YES |
27 |
Correct |
1 ms |
2812 KB |
answer = YES |
28 |
Correct |
1 ms |
2904 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2816 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2732 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2808 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2904 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2648 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2648 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2808 KB |
answer = YES |
17 |
Correct |
2 ms |
2652 KB |
answer = YES |
18 |
Correct |
2 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
2 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
2 ms |
2652 KB |
answer = YES |
27 |
Correct |
1 ms |
2812 KB |
answer = YES |
28 |
Correct |
1 ms |
2904 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2816 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2732 KB |
answer = YES |
37 |
Correct |
1 ms |
2648 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2908 KB |
answer = YES |
40 |
Correct |
3 ms |
2908 KB |
answer = YES |
41 |
Correct |
2 ms |
2908 KB |
answer = NO |
42 |
Correct |
2 ms |
2908 KB |
answer = YES |
43 |
Correct |
2 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
1 ms |
2828 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2808 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2904 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2648 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2648 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2808 KB |
answer = YES |
17 |
Correct |
2 ms |
2652 KB |
answer = YES |
18 |
Correct |
2 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
2 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
2 ms |
2652 KB |
answer = YES |
27 |
Correct |
1 ms |
2812 KB |
answer = YES |
28 |
Correct |
1 ms |
2904 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2816 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2732 KB |
answer = YES |
37 |
Correct |
1 ms |
2648 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2908 KB |
answer = YES |
40 |
Correct |
3 ms |
2908 KB |
answer = YES |
41 |
Correct |
2 ms |
2908 KB |
answer = NO |
42 |
Correct |
2 ms |
2908 KB |
answer = YES |
43 |
Correct |
2 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
1 ms |
2828 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
49 |
Correct |
8 ms |
4152 KB |
answer = YES |
50 |
Correct |
7 ms |
4320 KB |
answer = YES |
51 |
Correct |
8 ms |
4432 KB |
answer = YES |
52 |
Correct |
4 ms |
3932 KB |
answer = NO |
53 |
Correct |
2 ms |
2908 KB |
answer = YES |
54 |
Correct |
3 ms |
3080 KB |
answer = YES |
55 |
Correct |
5 ms |
3420 KB |
answer = YES |
56 |
Correct |
7 ms |
4052 KB |
answer = YES |
57 |
Correct |
7 ms |
3928 KB |
answer = YES |
58 |
Correct |
7 ms |
3928 KB |
answer = YES |
59 |
Correct |
7 ms |
3744 KB |
answer = YES |
60 |
Correct |
7 ms |
4088 KB |
answer = YES |
61 |
Correct |
5 ms |
3420 KB |
answer = YES |
62 |
Correct |
57 ms |
10436 KB |
answer = NO |
63 |
Correct |
45 ms |
10624 KB |
answer = YES |
64 |
Correct |
43 ms |
10576 KB |
answer = NO |
65 |
Correct |
53 ms |
10652 KB |
answer = YES |
66 |
Correct |
2 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2808 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2904 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2648 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2648 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2808 KB |
answer = YES |
17 |
Correct |
2 ms |
2652 KB |
answer = YES |
18 |
Correct |
2 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
2 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
2 ms |
2652 KB |
answer = YES |
27 |
Correct |
1 ms |
2812 KB |
answer = YES |
28 |
Correct |
1 ms |
2904 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2816 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2732 KB |
answer = YES |
37 |
Correct |
1 ms |
2648 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2908 KB |
answer = YES |
40 |
Correct |
3 ms |
2908 KB |
answer = YES |
41 |
Correct |
2 ms |
2908 KB |
answer = NO |
42 |
Correct |
2 ms |
2908 KB |
answer = YES |
43 |
Correct |
2 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
1 ms |
2828 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
49 |
Correct |
8 ms |
4152 KB |
answer = YES |
50 |
Correct |
7 ms |
4320 KB |
answer = YES |
51 |
Correct |
8 ms |
4432 KB |
answer = YES |
52 |
Correct |
4 ms |
3932 KB |
answer = NO |
53 |
Correct |
2 ms |
2908 KB |
answer = YES |
54 |
Correct |
3 ms |
3080 KB |
answer = YES |
55 |
Correct |
5 ms |
3420 KB |
answer = YES |
56 |
Correct |
7 ms |
4052 KB |
answer = YES |
57 |
Correct |
7 ms |
3928 KB |
answer = YES |
58 |
Correct |
7 ms |
3928 KB |
answer = YES |
59 |
Correct |
7 ms |
3744 KB |
answer = YES |
60 |
Correct |
7 ms |
4088 KB |
answer = YES |
61 |
Correct |
5 ms |
3420 KB |
answer = YES |
62 |
Correct |
57 ms |
10436 KB |
answer = NO |
63 |
Correct |
45 ms |
10624 KB |
answer = YES |
64 |
Correct |
43 ms |
10576 KB |
answer = NO |
65 |
Correct |
53 ms |
10652 KB |
answer = YES |
66 |
Correct |
2 ms |
2908 KB |
answer = YES |
67 |
Correct |
80 ms |
20804 KB |
answer = YES |
68 |
Correct |
65 ms |
20804 KB |
answer = YES |
69 |
Correct |
64 ms |
20428 KB |
answer = YES |
70 |
Correct |
80 ms |
25028 KB |
answer = YES |
71 |
Correct |
61 ms |
20372 KB |
answer = YES |
72 |
Correct |
70 ms |
15172 KB |
answer = YES |
73 |
Correct |
68 ms |
14792 KB |
answer = YES |
74 |
Correct |
47 ms |
13516 KB |
answer = YES |
75 |
Correct |
20 ms |
11480 KB |
answer = NO |
76 |
Correct |
9 ms |
4400 KB |
answer = YES |
77 |
Correct |
18 ms |
5844 KB |
answer = YES |
78 |
Correct |
31 ms |
8020 KB |
answer = YES |
79 |
Correct |
60 ms |
13136 KB |
answer = YES |
80 |
Correct |
50 ms |
13644 KB |
answer = YES |
81 |
Correct |
29 ms |
14536 KB |
answer = NO |
82 |
Correct |
82 ms |
19916 KB |
answer = YES |
83 |
Correct |
78 ms |
20680 KB |
answer = YES |
84 |
Correct |
83 ms |
20804 KB |
answer = YES |
85 |
Correct |
73 ms |
20760 KB |
answer = YES |
86 |
Correct |
69 ms |
20688 KB |
answer = YES |
87 |
Correct |
37 ms |
13016 KB |
answer = NO |
88 |
Correct |
75 ms |
16804 KB |
answer = YES |
89 |
Correct |
65 ms |
14852 KB |
answer = YES |
90 |
Correct |
59 ms |
14600 KB |
answer = YES |
91 |
Correct |
67 ms |
14600 KB |
answer = YES |
92 |
Correct |
32 ms |
8928 KB |
answer = YES |
93 |
Correct |
30 ms |
8916 KB |
answer = YES |
94 |
Correct |
38 ms |
17612 KB |
answer = NO |
95 |
Correct |
30 ms |
11916 KB |
answer = NO |
96 |
Correct |
100 ms |
22296 KB |
answer = YES |
97 |
Correct |
33 ms |
17612 KB |
answer = NO |