#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> pii;
const int INF = 1e9;
const int MAXN = 2e5 + 10;
bool d1[MAXN];
int d2[MAXN];
int cost[MAXN];
bool mark1[MAXN];
bool mark2[MAXN];
vector <pii> e[MAXN];
vector <int> vec;
void dfs1(int v, int val)
{
mark1[v] = true;
cost[v] = val;
for (auto [u, w] : e[v])
{
if (mark1[u])
{
if (cost[v] + cost[u] != 2 * w)
{
cout << "NO" << endl;
exit(0);
}
}
else
{
dfs1(u, 2 * w - val);
}
}
}
int dfs2(int v)
{
mark2[v] = true;
vec.push_back((d1[v] ? d2[v] : -d2[v]));
for (auto [u, w] : e[v])
{
if (!mark2[u])
{
d1[u] = !d1[v];
d2[u] = 2 * w - d2[v];
int x = dfs2(u);
if (x < INF)
return x;
}
else
{
if (d1[v] ^ d1[u])
{
if (2 * w - d2[v] != d2[u])
{
cout << "NO" << endl;
exit(0);
}
}
else
{
return (w - (d2[v] + d2[u]) / 2) * (d1[v] ? -1 : 1);
}
}
}
return INF;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int v, u, w;
cin >> v >> u >> w;
e[v].push_back({u, w});
e[u].push_back({v, w});
}
for (int i = 1; i <= n; i++)
{
if (mark1[i])
continue;
int x = dfs2(i);
if (x == INF)
{
sort(vec.begin(), vec.end());
x = vec[(vec.size() / 2)];
}
dfs1(i, x);
vec.clear();
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
cout << (float) (cost[i] / (float) 2) << " ";
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6756 KB |
answer = YES |
3 |
Correct |
2 ms |
6736 KB |
answer = YES |
4 |
Correct |
2 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
2 ms |
6736 KB |
answer = YES |
7 |
Correct |
2 ms |
6736 KB |
answer = YES |
8 |
Correct |
2 ms |
6736 KB |
answer = YES |
9 |
Correct |
2 ms |
6736 KB |
answer = NO |
10 |
Correct |
2 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6908 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
3 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
2 ms |
6736 KB |
answer = YES |
16 |
Correct |
2 ms |
6736 KB |
answer = YES |
17 |
Correct |
2 ms |
6736 KB |
answer = YES |
18 |
Correct |
2 ms |
6736 KB |
answer = YES |
19 |
Correct |
2 ms |
6736 KB |
answer = YES |
20 |
Correct |
2 ms |
6736 KB |
answer = YES |
21 |
Correct |
2 ms |
6736 KB |
answer = YES |
22 |
Correct |
2 ms |
6736 KB |
answer = NO |
23 |
Correct |
2 ms |
6736 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6756 KB |
answer = YES |
3 |
Correct |
2 ms |
6736 KB |
answer = YES |
4 |
Correct |
2 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
2 ms |
6736 KB |
answer = YES |
7 |
Correct |
2 ms |
6736 KB |
answer = YES |
8 |
Correct |
2 ms |
6736 KB |
answer = YES |
9 |
Correct |
2 ms |
6736 KB |
answer = NO |
10 |
Correct |
2 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6908 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
3 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
2 ms |
6736 KB |
answer = YES |
16 |
Correct |
2 ms |
6736 KB |
answer = YES |
17 |
Correct |
2 ms |
6736 KB |
answer = YES |
18 |
Correct |
2 ms |
6736 KB |
answer = YES |
19 |
Correct |
2 ms |
6736 KB |
answer = YES |
20 |
Correct |
2 ms |
6736 KB |
answer = YES |
21 |
Correct |
2 ms |
6736 KB |
answer = YES |
22 |
Correct |
2 ms |
6736 KB |
answer = NO |
23 |
Correct |
2 ms |
6736 KB |
answer = NO |
24 |
Correct |
2 ms |
6904 KB |
answer = YES |
25 |
Correct |
2 ms |
6736 KB |
answer = YES |
26 |
Correct |
2 ms |
6736 KB |
answer = YES |
27 |
Correct |
2 ms |
6736 KB |
answer = YES |
28 |
Correct |
2 ms |
6736 KB |
answer = YES |
29 |
Correct |
2 ms |
6736 KB |
answer = YES |
30 |
Correct |
2 ms |
6736 KB |
answer = NO |
31 |
Correct |
2 ms |
6736 KB |
answer = YES |
32 |
Correct |
2 ms |
6736 KB |
answer = YES |
33 |
Correct |
2 ms |
6736 KB |
answer = YES |
34 |
Correct |
2 ms |
6736 KB |
answer = YES |
35 |
Correct |
2 ms |
6736 KB |
answer = YES |
36 |
Correct |
2 ms |
6736 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6756 KB |
answer = YES |
3 |
Correct |
2 ms |
6736 KB |
answer = YES |
4 |
Correct |
2 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
2 ms |
6736 KB |
answer = YES |
7 |
Correct |
2 ms |
6736 KB |
answer = YES |
8 |
Correct |
2 ms |
6736 KB |
answer = YES |
9 |
Correct |
2 ms |
6736 KB |
answer = NO |
10 |
Correct |
2 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6908 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
3 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
2 ms |
6736 KB |
answer = YES |
16 |
Correct |
2 ms |
6736 KB |
answer = YES |
17 |
Correct |
2 ms |
6736 KB |
answer = YES |
18 |
Correct |
2 ms |
6736 KB |
answer = YES |
19 |
Correct |
2 ms |
6736 KB |
answer = YES |
20 |
Correct |
2 ms |
6736 KB |
answer = YES |
21 |
Correct |
2 ms |
6736 KB |
answer = YES |
22 |
Correct |
2 ms |
6736 KB |
answer = NO |
23 |
Correct |
2 ms |
6736 KB |
answer = NO |
24 |
Correct |
2 ms |
6904 KB |
answer = YES |
25 |
Correct |
2 ms |
6736 KB |
answer = YES |
26 |
Correct |
2 ms |
6736 KB |
answer = YES |
27 |
Correct |
2 ms |
6736 KB |
answer = YES |
28 |
Correct |
2 ms |
6736 KB |
answer = YES |
29 |
Correct |
2 ms |
6736 KB |
answer = YES |
30 |
Correct |
2 ms |
6736 KB |
answer = NO |
31 |
Correct |
2 ms |
6736 KB |
answer = YES |
32 |
Correct |
2 ms |
6736 KB |
answer = YES |
33 |
Correct |
2 ms |
6736 KB |
answer = YES |
34 |
Correct |
2 ms |
6736 KB |
answer = YES |
35 |
Correct |
2 ms |
6736 KB |
answer = YES |
36 |
Correct |
2 ms |
6736 KB |
answer = YES |
37 |
Correct |
2 ms |
6736 KB |
answer = YES |
38 |
Correct |
2 ms |
6736 KB |
answer = YES |
39 |
Correct |
2 ms |
6908 KB |
answer = YES |
40 |
Correct |
2 ms |
6736 KB |
answer = YES |
41 |
Correct |
3 ms |
6736 KB |
answer = NO |
42 |
Correct |
2 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
2 ms |
6736 KB |
answer = YES |
45 |
Correct |
3 ms |
6736 KB |
answer = YES |
46 |
Correct |
2 ms |
6736 KB |
answer = YES |
47 |
Correct |
3 ms |
6736 KB |
answer = YES |
48 |
Correct |
3 ms |
6776 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6756 KB |
answer = YES |
3 |
Correct |
2 ms |
6736 KB |
answer = YES |
4 |
Correct |
2 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
2 ms |
6736 KB |
answer = YES |
7 |
Correct |
2 ms |
6736 KB |
answer = YES |
8 |
Correct |
2 ms |
6736 KB |
answer = YES |
9 |
Correct |
2 ms |
6736 KB |
answer = NO |
10 |
Correct |
2 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6908 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
3 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
2 ms |
6736 KB |
answer = YES |
16 |
Correct |
2 ms |
6736 KB |
answer = YES |
17 |
Correct |
2 ms |
6736 KB |
answer = YES |
18 |
Correct |
2 ms |
6736 KB |
answer = YES |
19 |
Correct |
2 ms |
6736 KB |
answer = YES |
20 |
Correct |
2 ms |
6736 KB |
answer = YES |
21 |
Correct |
2 ms |
6736 KB |
answer = YES |
22 |
Correct |
2 ms |
6736 KB |
answer = NO |
23 |
Correct |
2 ms |
6736 KB |
answer = NO |
24 |
Correct |
2 ms |
6904 KB |
answer = YES |
25 |
Correct |
2 ms |
6736 KB |
answer = YES |
26 |
Correct |
2 ms |
6736 KB |
answer = YES |
27 |
Correct |
2 ms |
6736 KB |
answer = YES |
28 |
Correct |
2 ms |
6736 KB |
answer = YES |
29 |
Correct |
2 ms |
6736 KB |
answer = YES |
30 |
Correct |
2 ms |
6736 KB |
answer = NO |
31 |
Correct |
2 ms |
6736 KB |
answer = YES |
32 |
Correct |
2 ms |
6736 KB |
answer = YES |
33 |
Correct |
2 ms |
6736 KB |
answer = YES |
34 |
Correct |
2 ms |
6736 KB |
answer = YES |
35 |
Correct |
2 ms |
6736 KB |
answer = YES |
36 |
Correct |
2 ms |
6736 KB |
answer = YES |
37 |
Correct |
2 ms |
6736 KB |
answer = YES |
38 |
Correct |
2 ms |
6736 KB |
answer = YES |
39 |
Correct |
2 ms |
6908 KB |
answer = YES |
40 |
Correct |
2 ms |
6736 KB |
answer = YES |
41 |
Correct |
3 ms |
6736 KB |
answer = NO |
42 |
Correct |
2 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
2 ms |
6736 KB |
answer = YES |
45 |
Correct |
3 ms |
6736 KB |
answer = YES |
46 |
Correct |
2 ms |
6736 KB |
answer = YES |
47 |
Correct |
3 ms |
6736 KB |
answer = YES |
48 |
Correct |
3 ms |
6776 KB |
answer = YES |
49 |
Correct |
14 ms |
7248 KB |
answer = YES |
50 |
Correct |
17 ms |
7504 KB |
answer = YES |
51 |
Correct |
11 ms |
7504 KB |
answer = YES |
52 |
Correct |
7 ms |
6992 KB |
answer = NO |
53 |
Correct |
3 ms |
6904 KB |
answer = YES |
54 |
Correct |
4 ms |
6736 KB |
answer = YES |
55 |
Correct |
5 ms |
6884 KB |
answer = YES |
56 |
Correct |
9 ms |
7272 KB |
answer = YES |
57 |
Correct |
9 ms |
7140 KB |
answer = YES |
58 |
Correct |
8 ms |
6992 KB |
answer = YES |
59 |
Correct |
8 ms |
6992 KB |
answer = YES |
60 |
Correct |
9 ms |
7248 KB |
answer = YES |
61 |
Correct |
5 ms |
7164 KB |
answer = YES |
62 |
Correct |
82 ms |
11348 KB |
answer = NO |
63 |
Correct |
85 ms |
11848 KB |
answer = YES |
64 |
Correct |
100 ms |
11848 KB |
answer = NO |
65 |
Correct |
88 ms |
11848 KB |
answer = YES |
66 |
Correct |
3 ms |
6904 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6756 KB |
answer = YES |
3 |
Correct |
2 ms |
6736 KB |
answer = YES |
4 |
Correct |
2 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
2 ms |
6736 KB |
answer = YES |
7 |
Correct |
2 ms |
6736 KB |
answer = YES |
8 |
Correct |
2 ms |
6736 KB |
answer = YES |
9 |
Correct |
2 ms |
6736 KB |
answer = NO |
10 |
Correct |
2 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6908 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
3 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
2 ms |
6736 KB |
answer = YES |
16 |
Correct |
2 ms |
6736 KB |
answer = YES |
17 |
Correct |
2 ms |
6736 KB |
answer = YES |
18 |
Correct |
2 ms |
6736 KB |
answer = YES |
19 |
Correct |
2 ms |
6736 KB |
answer = YES |
20 |
Correct |
2 ms |
6736 KB |
answer = YES |
21 |
Correct |
2 ms |
6736 KB |
answer = YES |
22 |
Correct |
2 ms |
6736 KB |
answer = NO |
23 |
Correct |
2 ms |
6736 KB |
answer = NO |
24 |
Correct |
2 ms |
6904 KB |
answer = YES |
25 |
Correct |
2 ms |
6736 KB |
answer = YES |
26 |
Correct |
2 ms |
6736 KB |
answer = YES |
27 |
Correct |
2 ms |
6736 KB |
answer = YES |
28 |
Correct |
2 ms |
6736 KB |
answer = YES |
29 |
Correct |
2 ms |
6736 KB |
answer = YES |
30 |
Correct |
2 ms |
6736 KB |
answer = NO |
31 |
Correct |
2 ms |
6736 KB |
answer = YES |
32 |
Correct |
2 ms |
6736 KB |
answer = YES |
33 |
Correct |
2 ms |
6736 KB |
answer = YES |
34 |
Correct |
2 ms |
6736 KB |
answer = YES |
35 |
Correct |
2 ms |
6736 KB |
answer = YES |
36 |
Correct |
2 ms |
6736 KB |
answer = YES |
37 |
Correct |
2 ms |
6736 KB |
answer = YES |
38 |
Correct |
2 ms |
6736 KB |
answer = YES |
39 |
Correct |
2 ms |
6908 KB |
answer = YES |
40 |
Correct |
2 ms |
6736 KB |
answer = YES |
41 |
Correct |
3 ms |
6736 KB |
answer = NO |
42 |
Correct |
2 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
2 ms |
6736 KB |
answer = YES |
45 |
Correct |
3 ms |
6736 KB |
answer = YES |
46 |
Correct |
2 ms |
6736 KB |
answer = YES |
47 |
Correct |
3 ms |
6736 KB |
answer = YES |
48 |
Correct |
3 ms |
6776 KB |
answer = YES |
49 |
Correct |
14 ms |
7248 KB |
answer = YES |
50 |
Correct |
17 ms |
7504 KB |
answer = YES |
51 |
Correct |
11 ms |
7504 KB |
answer = YES |
52 |
Correct |
7 ms |
6992 KB |
answer = NO |
53 |
Correct |
3 ms |
6904 KB |
answer = YES |
54 |
Correct |
4 ms |
6736 KB |
answer = YES |
55 |
Correct |
5 ms |
6884 KB |
answer = YES |
56 |
Correct |
9 ms |
7272 KB |
answer = YES |
57 |
Correct |
9 ms |
7140 KB |
answer = YES |
58 |
Correct |
8 ms |
6992 KB |
answer = YES |
59 |
Correct |
8 ms |
6992 KB |
answer = YES |
60 |
Correct |
9 ms |
7248 KB |
answer = YES |
61 |
Correct |
5 ms |
7164 KB |
answer = YES |
62 |
Correct |
82 ms |
11348 KB |
answer = NO |
63 |
Correct |
85 ms |
11848 KB |
answer = YES |
64 |
Correct |
100 ms |
11848 KB |
answer = NO |
65 |
Correct |
88 ms |
11848 KB |
answer = YES |
66 |
Correct |
3 ms |
6904 KB |
answer = YES |
67 |
Correct |
90 ms |
18632 KB |
answer = YES |
68 |
Correct |
113 ms |
18376 KB |
answer = YES |
69 |
Correct |
79 ms |
18380 KB |
answer = YES |
70 |
Correct |
131 ms |
21444 KB |
answer = YES |
71 |
Correct |
91 ms |
18632 KB |
answer = YES |
72 |
Correct |
99 ms |
11204 KB |
answer = YES |
73 |
Correct |
78 ms |
10904 KB |
answer = YES |
74 |
Correct |
58 ms |
12364 KB |
answer = YES |
75 |
Correct |
36 ms |
11088 KB |
answer = NO |
76 |
Correct |
11 ms |
7248 KB |
answer = YES |
77 |
Correct |
23 ms |
7760 KB |
answer = YES |
78 |
Correct |
39 ms |
8784 KB |
answer = YES |
79 |
Correct |
79 ms |
10696 KB |
answer = YES |
80 |
Correct |
60 ms |
13292 KB |
answer = YES |
81 |
Correct |
62 ms |
13368 KB |
answer = NO |
82 |
Correct |
91 ms |
16332 KB |
answer = YES |
83 |
Correct |
131 ms |
18632 KB |
answer = YES |
84 |
Correct |
98 ms |
18512 KB |
answer = YES |
85 |
Correct |
90 ms |
18632 KB |
answer = YES |
86 |
Correct |
125 ms |
18516 KB |
answer = YES |
87 |
Correct |
81 ms |
12360 KB |
answer = NO |
88 |
Correct |
100 ms |
14040 KB |
answer = YES |
89 |
Correct |
80 ms |
10056 KB |
answer = YES |
90 |
Correct |
88 ms |
10056 KB |
answer = YES |
91 |
Correct |
102 ms |
10056 KB |
answer = YES |
92 |
Correct |
42 ms |
9032 KB |
answer = YES |
93 |
Correct |
42 ms |
8800 KB |
answer = YES |
94 |
Correct |
66 ms |
18228 KB |
answer = NO |
95 |
Correct |
56 ms |
9800 KB |
answer = NO |
96 |
Correct |
181 ms |
17224 KB |
answer = YES |
97 |
Correct |
60 ms |
18104 KB |
answer = NO |