# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
573637 |
2022-06-07T03:32:09 Z |
tengiz05 |
Graph (BOI20_graph) |
C++17 |
|
181 ms |
20016 KB |
#include <bits/stdc++.h>
using i64 = long long;
constexpr int inf = 1E9;
void gg() {
std::cout << "NO\n";
std::exit(0);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<std::pair<int, int>>> adj(n);
for (int i = 0; i < m; i++) {
int u, v, c;
std::cin >> u >> v >> c;
u--;
v--;
adj[u].emplace_back(v, c);
adj[v].emplace_back(u, c);
}
std::vector<bool> vis(n);
std::vector<int> col(n), a(n);
std::vector<double> ans(n);
for (int u = 0; u < n; u++) {
if (!vis[u]) {
int res[2] {inf, inf};
std::vector<int> b;
std::function<void(int)> dfs = [&](int u) {
vis[u] = true;
for (auto [v, c] : adj[u]) {
if (!vis[v]) {
col[v] = col[u] ^ 1;
a[v] = c - a[u];
dfs(v);
} else {
if (col[u] != col[v]) {
if (a[u] + a[v] != c) {
gg();
}
} else {
if (res[col[u]] == inf) {
res[col[u]] = c - a[u] - a[v];
} else if (res[col[u]] != c - a[u] - a[v]) {
gg();
}
}
}
}
b.push_back(u);
};
dfs(u);
if (res[0] != inf) {
if (res[1] != inf && res[1] != -res[0]) {
gg();
}
res[1] = -res[0];
} else if (res[1] != inf) {
res[0] = -res[1];
}
if (res[0] != inf) {
for (int v : b) {
ans[v] = a[v] + res[col[v]] / 2.;
}
} else {
std::pair<int, int> best(inf, -1);
for (int i = -100; i <= 100; i++) {
int sum = 0;
for (int v : b) {
sum += std::abs(a[v] + (col[v] == 0 ? i : -i));
}
best = std::min(best, std::pair(sum, i));
}
for (int v : b) {
ans[v] = a[v] + (col[v] == 0 ? best.second : -best.second);
}
}
}
}
std::cout << "YES\n";
for (int i = 0; i < n; i++) {
std::cout << ans[i] << " \n"[i == n - 1];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
0 ms |
212 KB |
answer = YES |
6 |
Correct |
1 ms |
212 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
0 ms |
212 KB |
answer = YES |
9 |
Correct |
0 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
212 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
1 ms |
212 KB |
answer = YES |
14 |
Correct |
0 ms |
212 KB |
answer = YES |
15 |
Correct |
1 ms |
212 KB |
answer = YES |
16 |
Correct |
0 ms |
212 KB |
answer = YES |
17 |
Correct |
0 ms |
212 KB |
answer = YES |
18 |
Correct |
0 ms |
212 KB |
answer = YES |
19 |
Correct |
0 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
212 KB |
answer = YES |
21 |
Correct |
0 ms |
212 KB |
answer = YES |
22 |
Correct |
1 ms |
212 KB |
answer = NO |
23 |
Correct |
0 ms |
212 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
0 ms |
212 KB |
answer = YES |
6 |
Correct |
1 ms |
212 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
0 ms |
212 KB |
answer = YES |
9 |
Correct |
0 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
212 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
1 ms |
212 KB |
answer = YES |
14 |
Correct |
0 ms |
212 KB |
answer = YES |
15 |
Correct |
1 ms |
212 KB |
answer = YES |
16 |
Correct |
0 ms |
212 KB |
answer = YES |
17 |
Correct |
0 ms |
212 KB |
answer = YES |
18 |
Correct |
0 ms |
212 KB |
answer = YES |
19 |
Correct |
0 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
212 KB |
answer = YES |
21 |
Correct |
0 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 |
212 KB |
answer = YES |
25 |
Correct |
0 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
1 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
0 ms |
212 KB |
answer = NO |
31 |
Correct |
0 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
0 ms |
212 KB |
answer = YES |
34 |
Correct |
0 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
0 ms |
212 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
0 ms |
212 KB |
answer = YES |
6 |
Correct |
1 ms |
212 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
0 ms |
212 KB |
answer = YES |
9 |
Correct |
0 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
212 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
1 ms |
212 KB |
answer = YES |
14 |
Correct |
0 ms |
212 KB |
answer = YES |
15 |
Correct |
1 ms |
212 KB |
answer = YES |
16 |
Correct |
0 ms |
212 KB |
answer = YES |
17 |
Correct |
0 ms |
212 KB |
answer = YES |
18 |
Correct |
0 ms |
212 KB |
answer = YES |
19 |
Correct |
0 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
212 KB |
answer = YES |
21 |
Correct |
0 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 |
212 KB |
answer = YES |
25 |
Correct |
0 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
1 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
0 ms |
212 KB |
answer = NO |
31 |
Correct |
0 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
0 ms |
212 KB |
answer = YES |
34 |
Correct |
0 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
0 ms |
212 KB |
answer = YES |
37 |
Correct |
1 ms |
212 KB |
answer = YES |
38 |
Correct |
1 ms |
212 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
340 KB |
answer = YES |
41 |
Correct |
1 ms |
340 KB |
answer = NO |
42 |
Correct |
1 ms |
340 KB |
answer = YES |
43 |
Correct |
1 ms |
340 KB |
answer = YES |
44 |
Correct |
2 ms |
340 KB |
answer = YES |
45 |
Correct |
1 ms |
340 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
340 KB |
answer = YES |
48 |
Correct |
1 ms |
340 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
0 ms |
212 KB |
answer = YES |
6 |
Correct |
1 ms |
212 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
0 ms |
212 KB |
answer = YES |
9 |
Correct |
0 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
212 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
1 ms |
212 KB |
answer = YES |
14 |
Correct |
0 ms |
212 KB |
answer = YES |
15 |
Correct |
1 ms |
212 KB |
answer = YES |
16 |
Correct |
0 ms |
212 KB |
answer = YES |
17 |
Correct |
0 ms |
212 KB |
answer = YES |
18 |
Correct |
0 ms |
212 KB |
answer = YES |
19 |
Correct |
0 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
212 KB |
answer = YES |
21 |
Correct |
0 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 |
212 KB |
answer = YES |
25 |
Correct |
0 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
1 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
0 ms |
212 KB |
answer = NO |
31 |
Correct |
0 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
0 ms |
212 KB |
answer = YES |
34 |
Correct |
0 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
0 ms |
212 KB |
answer = YES |
37 |
Correct |
1 ms |
212 KB |
answer = YES |
38 |
Correct |
1 ms |
212 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
340 KB |
answer = YES |
41 |
Correct |
1 ms |
340 KB |
answer = NO |
42 |
Correct |
1 ms |
340 KB |
answer = YES |
43 |
Correct |
1 ms |
340 KB |
answer = YES |
44 |
Correct |
2 ms |
340 KB |
answer = YES |
45 |
Correct |
1 ms |
340 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
340 KB |
answer = YES |
48 |
Correct |
1 ms |
340 KB |
answer = YES |
49 |
Correct |
10 ms |
1208 KB |
answer = YES |
50 |
Correct |
8 ms |
1492 KB |
answer = YES |
51 |
Correct |
11 ms |
1492 KB |
answer = YES |
52 |
Correct |
3 ms |
980 KB |
answer = NO |
53 |
Correct |
2 ms |
340 KB |
answer = YES |
54 |
Correct |
2 ms |
468 KB |
answer = YES |
55 |
Correct |
6 ms |
724 KB |
answer = YES |
56 |
Correct |
13 ms |
1212 KB |
answer = YES |
57 |
Correct |
10 ms |
1108 KB |
answer = YES |
58 |
Correct |
9 ms |
980 KB |
answer = YES |
59 |
Correct |
7 ms |
1108 KB |
answer = YES |
60 |
Correct |
10 ms |
1108 KB |
answer = YES |
61 |
Correct |
4 ms |
760 KB |
answer = YES |
62 |
Correct |
45 ms |
5260 KB |
answer = NO |
63 |
Correct |
73 ms |
5752 KB |
answer = YES |
64 |
Correct |
54 ms |
5708 KB |
answer = NO |
65 |
Correct |
49 ms |
5764 KB |
answer = YES |
66 |
Correct |
2 ms |
468 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
0 ms |
212 KB |
answer = YES |
3 |
Correct |
1 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Correct |
0 ms |
212 KB |
answer = YES |
6 |
Correct |
1 ms |
212 KB |
answer = YES |
7 |
Correct |
1 ms |
212 KB |
answer = YES |
8 |
Correct |
0 ms |
212 KB |
answer = YES |
9 |
Correct |
0 ms |
212 KB |
answer = NO |
10 |
Correct |
1 ms |
212 KB |
answer = YES |
11 |
Correct |
0 ms |
212 KB |
answer = YES |
12 |
Correct |
0 ms |
212 KB |
answer = NO |
13 |
Correct |
1 ms |
212 KB |
answer = YES |
14 |
Correct |
0 ms |
212 KB |
answer = YES |
15 |
Correct |
1 ms |
212 KB |
answer = YES |
16 |
Correct |
0 ms |
212 KB |
answer = YES |
17 |
Correct |
0 ms |
212 KB |
answer = YES |
18 |
Correct |
0 ms |
212 KB |
answer = YES |
19 |
Correct |
0 ms |
212 KB |
answer = YES |
20 |
Correct |
0 ms |
212 KB |
answer = YES |
21 |
Correct |
0 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 |
212 KB |
answer = YES |
25 |
Correct |
0 ms |
212 KB |
answer = YES |
26 |
Correct |
1 ms |
212 KB |
answer = YES |
27 |
Correct |
1 ms |
212 KB |
answer = YES |
28 |
Correct |
1 ms |
212 KB |
answer = YES |
29 |
Correct |
1 ms |
212 KB |
answer = YES |
30 |
Correct |
0 ms |
212 KB |
answer = NO |
31 |
Correct |
0 ms |
212 KB |
answer = YES |
32 |
Correct |
0 ms |
212 KB |
answer = YES |
33 |
Correct |
0 ms |
212 KB |
answer = YES |
34 |
Correct |
0 ms |
212 KB |
answer = YES |
35 |
Correct |
1 ms |
212 KB |
answer = YES |
36 |
Correct |
0 ms |
212 KB |
answer = YES |
37 |
Correct |
1 ms |
212 KB |
answer = YES |
38 |
Correct |
1 ms |
212 KB |
answer = YES |
39 |
Correct |
1 ms |
340 KB |
answer = YES |
40 |
Correct |
1 ms |
340 KB |
answer = YES |
41 |
Correct |
1 ms |
340 KB |
answer = NO |
42 |
Correct |
1 ms |
340 KB |
answer = YES |
43 |
Correct |
1 ms |
340 KB |
answer = YES |
44 |
Correct |
2 ms |
340 KB |
answer = YES |
45 |
Correct |
1 ms |
340 KB |
answer = YES |
46 |
Correct |
1 ms |
340 KB |
answer = YES |
47 |
Correct |
1 ms |
340 KB |
answer = YES |
48 |
Correct |
1 ms |
340 KB |
answer = YES |
49 |
Correct |
10 ms |
1208 KB |
answer = YES |
50 |
Correct |
8 ms |
1492 KB |
answer = YES |
51 |
Correct |
11 ms |
1492 KB |
answer = YES |
52 |
Correct |
3 ms |
980 KB |
answer = NO |
53 |
Correct |
2 ms |
340 KB |
answer = YES |
54 |
Correct |
2 ms |
468 KB |
answer = YES |
55 |
Correct |
6 ms |
724 KB |
answer = YES |
56 |
Correct |
13 ms |
1212 KB |
answer = YES |
57 |
Correct |
10 ms |
1108 KB |
answer = YES |
58 |
Correct |
9 ms |
980 KB |
answer = YES |
59 |
Correct |
7 ms |
1108 KB |
answer = YES |
60 |
Correct |
10 ms |
1108 KB |
answer = YES |
61 |
Correct |
4 ms |
760 KB |
answer = YES |
62 |
Correct |
45 ms |
5260 KB |
answer = NO |
63 |
Correct |
73 ms |
5752 KB |
answer = YES |
64 |
Correct |
54 ms |
5708 KB |
answer = NO |
65 |
Correct |
49 ms |
5764 KB |
answer = YES |
66 |
Correct |
2 ms |
468 KB |
answer = YES |
67 |
Correct |
109 ms |
14188 KB |
answer = YES |
68 |
Correct |
99 ms |
15564 KB |
answer = YES |
69 |
Correct |
68 ms |
15612 KB |
answer = YES |
70 |
Correct |
98 ms |
20016 KB |
answer = YES |
71 |
Correct |
103 ms |
15560 KB |
answer = YES |
72 |
Correct |
145 ms |
9980 KB |
answer = YES |
73 |
Correct |
91 ms |
9928 KB |
answer = YES |
74 |
Correct |
55 ms |
9360 KB |
answer = YES |
75 |
Correct |
19 ms |
7320 KB |
answer = NO |
76 |
Correct |
13 ms |
1468 KB |
answer = YES |
77 |
Correct |
25 ms |
2772 KB |
answer = YES |
78 |
Correct |
50 ms |
4556 KB |
answer = YES |
79 |
Correct |
141 ms |
8652 KB |
answer = YES |
80 |
Correct |
79 ms |
9392 KB |
answer = YES |
81 |
Correct |
37 ms |
12256 KB |
answer = NO |
82 |
Correct |
94 ms |
15104 KB |
answer = YES |
83 |
Correct |
92 ms |
15580 KB |
answer = YES |
84 |
Correct |
181 ms |
15620 KB |
answer = YES |
85 |
Correct |
96 ms |
15560 KB |
answer = YES |
86 |
Correct |
73 ms |
15568 KB |
answer = YES |
87 |
Correct |
48 ms |
10584 KB |
answer = NO |
88 |
Correct |
94 ms |
11960 KB |
answer = YES |
89 |
Correct |
91 ms |
9008 KB |
answer = YES |
90 |
Correct |
81 ms |
8972 KB |
answer = YES |
91 |
Correct |
84 ms |
8976 KB |
answer = YES |
92 |
Correct |
41 ms |
5188 KB |
answer = YES |
93 |
Correct |
37 ms |
5196 KB |
answer = YES |
94 |
Correct |
45 ms |
14912 KB |
answer = NO |
95 |
Correct |
45 ms |
8660 KB |
answer = NO |
96 |
Correct |
166 ms |
17540 KB |
answer = YES |
97 |
Correct |
30 ms |
14868 KB |
answer = NO |