#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 |
6788 KB |
answer = YES |
3 |
Correct |
2 ms |
6904 KB |
answer = YES |
4 |
Correct |
1 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
1 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 |
1 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6904 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
2 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
1 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 |
1 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 |
6788 KB |
answer = YES |
3 |
Correct |
2 ms |
6904 KB |
answer = YES |
4 |
Correct |
1 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
1 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 |
1 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6904 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
2 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
1 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 |
1 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 |
6736 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 |
6764 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 |
6788 KB |
answer = YES |
3 |
Correct |
2 ms |
6904 KB |
answer = YES |
4 |
Correct |
1 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
1 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 |
1 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6904 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
2 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
1 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 |
1 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 |
6736 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 |
6764 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 |
6736 KB |
answer = YES |
40 |
Correct |
2 ms |
6808 KB |
answer = YES |
41 |
Correct |
2 ms |
6736 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
3 ms |
6736 KB |
answer = YES |
45 |
Correct |
2 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 |
6736 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6788 KB |
answer = YES |
3 |
Correct |
2 ms |
6904 KB |
answer = YES |
4 |
Correct |
1 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
1 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 |
1 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6904 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
2 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
1 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 |
1 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 |
6736 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 |
6764 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 |
6736 KB |
answer = YES |
40 |
Correct |
2 ms |
6808 KB |
answer = YES |
41 |
Correct |
2 ms |
6736 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
3 ms |
6736 KB |
answer = YES |
45 |
Correct |
2 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 |
6736 KB |
answer = YES |
49 |
Correct |
10 ms |
7248 KB |
answer = YES |
50 |
Correct |
10 ms |
7812 KB |
answer = YES |
51 |
Correct |
10 ms |
7760 KB |
answer = YES |
52 |
Correct |
6 ms |
7140 KB |
answer = NO |
53 |
Correct |
2 ms |
6736 KB |
answer = YES |
54 |
Correct |
4 ms |
6904 KB |
answer = YES |
55 |
Correct |
6 ms |
7004 KB |
answer = YES |
56 |
Correct |
9 ms |
7248 KB |
answer = YES |
57 |
Correct |
10 ms |
7248 KB |
answer = YES |
58 |
Correct |
8 ms |
7248 KB |
answer = YES |
59 |
Correct |
9 ms |
7416 KB |
answer = YES |
60 |
Correct |
11 ms |
7248 KB |
answer = YES |
61 |
Correct |
6 ms |
6992 KB |
answer = YES |
62 |
Correct |
88 ms |
13640 KB |
answer = NO |
63 |
Correct |
94 ms |
14152 KB |
answer = YES |
64 |
Correct |
90 ms |
14164 KB |
answer = NO |
65 |
Correct |
110 ms |
14152 KB |
answer = YES |
66 |
Correct |
3 ms |
6736 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
answer = YES |
2 |
Correct |
1 ms |
6788 KB |
answer = YES |
3 |
Correct |
2 ms |
6904 KB |
answer = YES |
4 |
Correct |
1 ms |
6736 KB |
answer = NO |
5 |
Correct |
2 ms |
6736 KB |
answer = YES |
6 |
Correct |
1 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 |
1 ms |
6736 KB |
answer = YES |
11 |
Correct |
2 ms |
6904 KB |
answer = YES |
12 |
Correct |
2 ms |
6736 KB |
answer = NO |
13 |
Correct |
2 ms |
6736 KB |
answer = YES |
14 |
Correct |
2 ms |
6736 KB |
answer = YES |
15 |
Correct |
1 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 |
1 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 |
6736 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 |
6764 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 |
6736 KB |
answer = YES |
40 |
Correct |
2 ms |
6808 KB |
answer = YES |
41 |
Correct |
2 ms |
6736 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
2 ms |
6736 KB |
answer = YES |
44 |
Correct |
3 ms |
6736 KB |
answer = YES |
45 |
Correct |
2 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 |
6736 KB |
answer = YES |
49 |
Correct |
10 ms |
7248 KB |
answer = YES |
50 |
Correct |
10 ms |
7812 KB |
answer = YES |
51 |
Correct |
10 ms |
7760 KB |
answer = YES |
52 |
Correct |
6 ms |
7140 KB |
answer = NO |
53 |
Correct |
2 ms |
6736 KB |
answer = YES |
54 |
Correct |
4 ms |
6904 KB |
answer = YES |
55 |
Correct |
6 ms |
7004 KB |
answer = YES |
56 |
Correct |
9 ms |
7248 KB |
answer = YES |
57 |
Correct |
10 ms |
7248 KB |
answer = YES |
58 |
Correct |
8 ms |
7248 KB |
answer = YES |
59 |
Correct |
9 ms |
7416 KB |
answer = YES |
60 |
Correct |
11 ms |
7248 KB |
answer = YES |
61 |
Correct |
6 ms |
6992 KB |
answer = YES |
62 |
Correct |
88 ms |
13640 KB |
answer = NO |
63 |
Correct |
94 ms |
14152 KB |
answer = YES |
64 |
Correct |
90 ms |
14164 KB |
answer = NO |
65 |
Correct |
110 ms |
14152 KB |
answer = YES |
66 |
Correct |
3 ms |
6736 KB |
answer = YES |
67 |
Correct |
90 ms |
19912 KB |
answer = YES |
68 |
Correct |
92 ms |
19656 KB |
answer = YES |
69 |
Correct |
89 ms |
19692 KB |
answer = YES |
70 |
Correct |
136 ms |
24196 KB |
answer = YES |
71 |
Correct |
88 ms |
19912 KB |
answer = YES |
72 |
Correct |
85 ms |
12648 KB |
answer = YES |
73 |
Correct |
83 ms |
12228 KB |
answer = YES |
74 |
Correct |
59 ms |
13200 KB |
answer = YES |
75 |
Correct |
39 ms |
11860 KB |
answer = NO |
76 |
Correct |
13 ms |
7520 KB |
answer = YES |
77 |
Correct |
24 ms |
8296 KB |
answer = YES |
78 |
Correct |
39 ms |
9288 KB |
answer = YES |
79 |
Correct |
78 ms |
11632 KB |
answer = YES |
80 |
Correct |
63 ms |
14288 KB |
answer = YES |
81 |
Correct |
62 ms |
14712 KB |
answer = NO |
82 |
Correct |
99 ms |
17876 KB |
answer = YES |
83 |
Correct |
108 ms |
20016 KB |
answer = YES |
84 |
Correct |
114 ms |
19960 KB |
answer = YES |
85 |
Correct |
96 ms |
19932 KB |
answer = YES |
86 |
Correct |
90 ms |
19800 KB |
answer = YES |
87 |
Correct |
60 ms |
13640 KB |
answer = NO |
88 |
Correct |
109 ms |
15308 KB |
answer = YES |
89 |
Correct |
93 ms |
11560 KB |
answer = YES |
90 |
Correct |
84 ms |
11512 KB |
answer = YES |
91 |
Correct |
87 ms |
11592 KB |
answer = YES |
92 |
Correct |
51 ms |
9688 KB |
answer = YES |
93 |
Correct |
42 ms |
9552 KB |
answer = YES |
94 |
Correct |
71 ms |
19496 KB |
answer = NO |
95 |
Correct |
55 ms |
11340 KB |
answer = NO |
96 |
Correct |
159 ms |
19772 KB |
answer = YES |
97 |
Correct |
60 ms |
19656 KB |
answer = NO |