# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
482970 |
2021-10-27T06:11:33 Z |
sberens |
Graph (BOI20_graph) |
C++17 |
|
241 ms |
28164 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename K> using hset = gp_hash_table<K, null_type>;
template <typename K, typename V> using hmap = gp_hash_table<K, V>;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define smax(x, y) (x = max(x, y))
#define smin(x, y) (x = min(x, y))
using ll = long long;
using ld = long double;
template <typename T>
using vv = vector<vector<T>>;
using vi = vector<int>;
using ii = array<int, 2>;
using vii = vector<ii>;
using vvi = vv<int>;
using vll = vector<ll>;
using l2 = array<ll, 2>;
using vl2 = vector<l2>;
using vvll = vv<ll>;
template <typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxq = priority_queue<T>;
const ll M = 1000000007;
int n, m;
vv<ii> g;
using valt = ii;
vector<set<valt>> coefs;
vi vis;
tuple<bool, vvi> solve() {
vvi comps;
for (int i = 1; i <= n; ++i) {
if (vis[i]) continue;
comps.pb({});
queue<tuple<int, valt>> q; // node, val
q.push({i, {1, 0}});
while (!q.empty()) {
auto [u, val] = q.front(); q.pop();
coefs[u].insert(val);
if (vis[u]) {
if (coefs[u].size() > 2) return {false, {}};
continue;
}
vis[u] = true;
comps.back().pb(u);
auto [a, b] = val;
for (auto [v, c]: g[u]) {
q.push({v, {-a, c-b}});
}
}
}
return {true, comps};
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
g.assign(n + 1, vii{});
coefs.assign(n + 1, set<valt>{});
vis.assign(n + 1, false);
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
g[a].pb({b, c});
g[b].pb({a, c});
}
auto [poss, comps] = solve();
if (poss) {
vector<long double> vals(n + 1);
for (const auto & comp : comps) {
vi pts;
long double x;
bool fixed = false;
for (int u : comp) {
auto [a, b] = *coefs[u].begin();
pts.pb(-a * b);
if (coefs[u].size() == 2) {
auto [a1, b1] = *coefs[u].begin();
auto [a2, b2] = *(++coefs[u].begin());
long double tmp = (b2 - b1) / (0.l + a1 - a2);
if (b1 == b2) tmp = 0;
if ((a1 == a2) || (fixed && fabs(tmp - x) > DBL_EPSILON)) {
cout << "NO\n";
exit(0);
}
x = tmp;
fixed = true;
}
}
if (!fixed) {
sort(all(pts));
if (pts.size() % 2 == 1) x = pts[pts.size() / 2];
else x = (pts[pts.size() / 2 - 1] + pts[pts.size() / 2]) / 2.l;
}
for (int u : comp) {
auto [a, b] = *coefs[u].begin();
vals[u] = a * x + b;
}
}
cout << "YES\n";
for (int i = 1; i <= n; ++i) {
cout << vals[i] << ' ';
}
cout << '\n';
} else {
cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
answer = YES |
2 |
Correct |
0 ms |
204 KB |
answer = YES |
3 |
Correct |
1 ms |
204 KB |
answer = YES |
4 |
Correct |
1 ms |
204 KB |
answer = NO |
5 |
Correct |
1 ms |
204 KB |
answer = YES |
6 |
Correct |
0 ms |
204 KB |
answer = YES |
7 |
Correct |
0 ms |
204 KB |
answer = YES |
8 |
Correct |
1 ms |
204 KB |
answer = YES |
9 |
Correct |
0 ms |
204 KB |
answer = NO |
10 |
Correct |
1 ms |
204 KB |
answer = YES |
11 |
Correct |
1 ms |
204 KB |
answer = YES |
12 |
Correct |
1 ms |
204 KB |
answer = NO |
13 |
Correct |
1 ms |
204 KB |
answer = YES |
14 |
Correct |
1 ms |
204 KB |
answer = YES |
15 |
Correct |
1 ms |
204 KB |
answer = YES |
16 |
Correct |
0 ms |
204 KB |
answer = YES |
17 |
Correct |
0 ms |
204 KB |
answer = YES |
18 |
Correct |
1 ms |
204 KB |
answer = YES |
19 |
Correct |
0 ms |
204 KB |
answer = YES |
20 |
Correct |
1 ms |
204 KB |
answer = YES |
21 |
Correct |
0 ms |
204 KB |
answer = YES |
22 |
Correct |
0 ms |
204 KB |
answer = NO |
23 |
Correct |
0 ms |
204 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
answer = YES |
2 |
Correct |
0 ms |
204 KB |
answer = YES |
3 |
Correct |
1 ms |
204 KB |
answer = YES |
4 |
Correct |
1 ms |
204 KB |
answer = NO |
5 |
Correct |
1 ms |
204 KB |
answer = YES |
6 |
Correct |
0 ms |
204 KB |
answer = YES |
7 |
Correct |
0 ms |
204 KB |
answer = YES |
8 |
Correct |
1 ms |
204 KB |
answer = YES |
9 |
Correct |
0 ms |
204 KB |
answer = NO |
10 |
Correct |
1 ms |
204 KB |
answer = YES |
11 |
Correct |
1 ms |
204 KB |
answer = YES |
12 |
Correct |
1 ms |
204 KB |
answer = NO |
13 |
Correct |
1 ms |
204 KB |
answer = YES |
14 |
Correct |
1 ms |
204 KB |
answer = YES |
15 |
Correct |
1 ms |
204 KB |
answer = YES |
16 |
Correct |
0 ms |
204 KB |
answer = YES |
17 |
Correct |
0 ms |
204 KB |
answer = YES |
18 |
Correct |
1 ms |
204 KB |
answer = YES |
19 |
Correct |
0 ms |
204 KB |
answer = YES |
20 |
Correct |
1 ms |
204 KB |
answer = YES |
21 |
Correct |
0 ms |
204 KB |
answer = YES |
22 |
Correct |
0 ms |
204 KB |
answer = NO |
23 |
Correct |
0 ms |
204 KB |
answer = NO |
24 |
Correct |
0 ms |
204 KB |
answer = YES |
25 |
Correct |
0 ms |
312 KB |
answer = YES |
26 |
Correct |
0 ms |
332 KB |
answer = YES |
27 |
Correct |
1 ms |
204 KB |
answer = YES |
28 |
Correct |
0 ms |
332 KB |
answer = YES |
29 |
Correct |
1 ms |
280 KB |
answer = YES |
30 |
Correct |
0 ms |
204 KB |
answer = NO |
31 |
Correct |
0 ms |
204 KB |
answer = YES |
32 |
Correct |
1 ms |
332 KB |
answer = YES |
33 |
Correct |
1 ms |
204 KB |
answer = YES |
34 |
Correct |
0 ms |
332 KB |
answer = YES |
35 |
Correct |
1 ms |
204 KB |
answer = YES |
36 |
Correct |
0 ms |
204 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
answer = YES |
2 |
Correct |
0 ms |
204 KB |
answer = YES |
3 |
Correct |
1 ms |
204 KB |
answer = YES |
4 |
Correct |
1 ms |
204 KB |
answer = NO |
5 |
Correct |
1 ms |
204 KB |
answer = YES |
6 |
Correct |
0 ms |
204 KB |
answer = YES |
7 |
Correct |
0 ms |
204 KB |
answer = YES |
8 |
Correct |
1 ms |
204 KB |
answer = YES |
9 |
Correct |
0 ms |
204 KB |
answer = NO |
10 |
Correct |
1 ms |
204 KB |
answer = YES |
11 |
Correct |
1 ms |
204 KB |
answer = YES |
12 |
Correct |
1 ms |
204 KB |
answer = NO |
13 |
Correct |
1 ms |
204 KB |
answer = YES |
14 |
Correct |
1 ms |
204 KB |
answer = YES |
15 |
Correct |
1 ms |
204 KB |
answer = YES |
16 |
Correct |
0 ms |
204 KB |
answer = YES |
17 |
Correct |
0 ms |
204 KB |
answer = YES |
18 |
Correct |
1 ms |
204 KB |
answer = YES |
19 |
Correct |
0 ms |
204 KB |
answer = YES |
20 |
Correct |
1 ms |
204 KB |
answer = YES |
21 |
Correct |
0 ms |
204 KB |
answer = YES |
22 |
Correct |
0 ms |
204 KB |
answer = NO |
23 |
Correct |
0 ms |
204 KB |
answer = NO |
24 |
Correct |
0 ms |
204 KB |
answer = YES |
25 |
Correct |
0 ms |
312 KB |
answer = YES |
26 |
Correct |
0 ms |
332 KB |
answer = YES |
27 |
Correct |
1 ms |
204 KB |
answer = YES |
28 |
Correct |
0 ms |
332 KB |
answer = YES |
29 |
Correct |
1 ms |
280 KB |
answer = YES |
30 |
Correct |
0 ms |
204 KB |
answer = NO |
31 |
Correct |
0 ms |
204 KB |
answer = YES |
32 |
Correct |
1 ms |
332 KB |
answer = YES |
33 |
Correct |
1 ms |
204 KB |
answer = YES |
34 |
Correct |
0 ms |
332 KB |
answer = YES |
35 |
Correct |
1 ms |
204 KB |
answer = YES |
36 |
Correct |
0 ms |
204 KB |
answer = YES |
37 |
Correct |
1 ms |
332 KB |
answer = YES |
38 |
Correct |
1 ms |
332 KB |
answer = YES |
39 |
Correct |
1 ms |
332 KB |
answer = YES |
40 |
Correct |
1 ms |
460 KB |
answer = YES |
41 |
Correct |
1 ms |
460 KB |
answer = NO |
42 |
Correct |
1 ms |
460 KB |
answer = YES |
43 |
Correct |
1 ms |
460 KB |
answer = YES |
44 |
Correct |
1 ms |
460 KB |
answer = YES |
45 |
Correct |
1 ms |
460 KB |
answer = YES |
46 |
Correct |
1 ms |
332 KB |
answer = YES |
47 |
Correct |
1 ms |
460 KB |
answer = YES |
48 |
Correct |
1 ms |
460 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
answer = YES |
2 |
Correct |
0 ms |
204 KB |
answer = YES |
3 |
Correct |
1 ms |
204 KB |
answer = YES |
4 |
Correct |
1 ms |
204 KB |
answer = NO |
5 |
Correct |
1 ms |
204 KB |
answer = YES |
6 |
Correct |
0 ms |
204 KB |
answer = YES |
7 |
Correct |
0 ms |
204 KB |
answer = YES |
8 |
Correct |
1 ms |
204 KB |
answer = YES |
9 |
Correct |
0 ms |
204 KB |
answer = NO |
10 |
Correct |
1 ms |
204 KB |
answer = YES |
11 |
Correct |
1 ms |
204 KB |
answer = YES |
12 |
Correct |
1 ms |
204 KB |
answer = NO |
13 |
Correct |
1 ms |
204 KB |
answer = YES |
14 |
Correct |
1 ms |
204 KB |
answer = YES |
15 |
Correct |
1 ms |
204 KB |
answer = YES |
16 |
Correct |
0 ms |
204 KB |
answer = YES |
17 |
Correct |
0 ms |
204 KB |
answer = YES |
18 |
Correct |
1 ms |
204 KB |
answer = YES |
19 |
Correct |
0 ms |
204 KB |
answer = YES |
20 |
Correct |
1 ms |
204 KB |
answer = YES |
21 |
Correct |
0 ms |
204 KB |
answer = YES |
22 |
Correct |
0 ms |
204 KB |
answer = NO |
23 |
Correct |
0 ms |
204 KB |
answer = NO |
24 |
Correct |
0 ms |
204 KB |
answer = YES |
25 |
Correct |
0 ms |
312 KB |
answer = YES |
26 |
Correct |
0 ms |
332 KB |
answer = YES |
27 |
Correct |
1 ms |
204 KB |
answer = YES |
28 |
Correct |
0 ms |
332 KB |
answer = YES |
29 |
Correct |
1 ms |
280 KB |
answer = YES |
30 |
Correct |
0 ms |
204 KB |
answer = NO |
31 |
Correct |
0 ms |
204 KB |
answer = YES |
32 |
Correct |
1 ms |
332 KB |
answer = YES |
33 |
Correct |
1 ms |
204 KB |
answer = YES |
34 |
Correct |
0 ms |
332 KB |
answer = YES |
35 |
Correct |
1 ms |
204 KB |
answer = YES |
36 |
Correct |
0 ms |
204 KB |
answer = YES |
37 |
Correct |
1 ms |
332 KB |
answer = YES |
38 |
Correct |
1 ms |
332 KB |
answer = YES |
39 |
Correct |
1 ms |
332 KB |
answer = YES |
40 |
Correct |
1 ms |
460 KB |
answer = YES |
41 |
Correct |
1 ms |
460 KB |
answer = NO |
42 |
Correct |
1 ms |
460 KB |
answer = YES |
43 |
Correct |
1 ms |
460 KB |
answer = YES |
44 |
Correct |
1 ms |
460 KB |
answer = YES |
45 |
Correct |
1 ms |
460 KB |
answer = YES |
46 |
Correct |
1 ms |
332 KB |
answer = YES |
47 |
Correct |
1 ms |
460 KB |
answer = YES |
48 |
Correct |
1 ms |
460 KB |
answer = YES |
49 |
Correct |
9 ms |
2252 KB |
answer = YES |
50 |
Correct |
9 ms |
2320 KB |
answer = YES |
51 |
Correct |
9 ms |
2252 KB |
answer = YES |
52 |
Correct |
5 ms |
2124 KB |
answer = NO |
53 |
Correct |
1 ms |
460 KB |
answer = YES |
54 |
Correct |
2 ms |
716 KB |
answer = YES |
55 |
Correct |
5 ms |
1228 KB |
answer = YES |
56 |
Correct |
10 ms |
2252 KB |
answer = YES |
57 |
Correct |
10 ms |
2244 KB |
answer = YES |
58 |
Correct |
8 ms |
2124 KB |
answer = YES |
59 |
Correct |
8 ms |
2124 KB |
answer = YES |
60 |
Correct |
9 ms |
2324 KB |
answer = YES |
61 |
Correct |
7 ms |
1356 KB |
answer = YES |
62 |
Correct |
49 ms |
8308 KB |
answer = NO |
63 |
Correct |
70 ms |
12228 KB |
answer = YES |
64 |
Correct |
74 ms |
12324 KB |
answer = NO |
65 |
Correct |
72 ms |
12284 KB |
answer = YES |
66 |
Correct |
2 ms |
716 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
answer = YES |
2 |
Correct |
0 ms |
204 KB |
answer = YES |
3 |
Correct |
1 ms |
204 KB |
answer = YES |
4 |
Correct |
1 ms |
204 KB |
answer = NO |
5 |
Correct |
1 ms |
204 KB |
answer = YES |
6 |
Correct |
0 ms |
204 KB |
answer = YES |
7 |
Correct |
0 ms |
204 KB |
answer = YES |
8 |
Correct |
1 ms |
204 KB |
answer = YES |
9 |
Correct |
0 ms |
204 KB |
answer = NO |
10 |
Correct |
1 ms |
204 KB |
answer = YES |
11 |
Correct |
1 ms |
204 KB |
answer = YES |
12 |
Correct |
1 ms |
204 KB |
answer = NO |
13 |
Correct |
1 ms |
204 KB |
answer = YES |
14 |
Correct |
1 ms |
204 KB |
answer = YES |
15 |
Correct |
1 ms |
204 KB |
answer = YES |
16 |
Correct |
0 ms |
204 KB |
answer = YES |
17 |
Correct |
0 ms |
204 KB |
answer = YES |
18 |
Correct |
1 ms |
204 KB |
answer = YES |
19 |
Correct |
0 ms |
204 KB |
answer = YES |
20 |
Correct |
1 ms |
204 KB |
answer = YES |
21 |
Correct |
0 ms |
204 KB |
answer = YES |
22 |
Correct |
0 ms |
204 KB |
answer = NO |
23 |
Correct |
0 ms |
204 KB |
answer = NO |
24 |
Correct |
0 ms |
204 KB |
answer = YES |
25 |
Correct |
0 ms |
312 KB |
answer = YES |
26 |
Correct |
0 ms |
332 KB |
answer = YES |
27 |
Correct |
1 ms |
204 KB |
answer = YES |
28 |
Correct |
0 ms |
332 KB |
answer = YES |
29 |
Correct |
1 ms |
280 KB |
answer = YES |
30 |
Correct |
0 ms |
204 KB |
answer = NO |
31 |
Correct |
0 ms |
204 KB |
answer = YES |
32 |
Correct |
1 ms |
332 KB |
answer = YES |
33 |
Correct |
1 ms |
204 KB |
answer = YES |
34 |
Correct |
0 ms |
332 KB |
answer = YES |
35 |
Correct |
1 ms |
204 KB |
answer = YES |
36 |
Correct |
0 ms |
204 KB |
answer = YES |
37 |
Correct |
1 ms |
332 KB |
answer = YES |
38 |
Correct |
1 ms |
332 KB |
answer = YES |
39 |
Correct |
1 ms |
332 KB |
answer = YES |
40 |
Correct |
1 ms |
460 KB |
answer = YES |
41 |
Correct |
1 ms |
460 KB |
answer = NO |
42 |
Correct |
1 ms |
460 KB |
answer = YES |
43 |
Correct |
1 ms |
460 KB |
answer = YES |
44 |
Correct |
1 ms |
460 KB |
answer = YES |
45 |
Correct |
1 ms |
460 KB |
answer = YES |
46 |
Correct |
1 ms |
332 KB |
answer = YES |
47 |
Correct |
1 ms |
460 KB |
answer = YES |
48 |
Correct |
1 ms |
460 KB |
answer = YES |
49 |
Correct |
9 ms |
2252 KB |
answer = YES |
50 |
Correct |
9 ms |
2320 KB |
answer = YES |
51 |
Correct |
9 ms |
2252 KB |
answer = YES |
52 |
Correct |
5 ms |
2124 KB |
answer = NO |
53 |
Correct |
1 ms |
460 KB |
answer = YES |
54 |
Correct |
2 ms |
716 KB |
answer = YES |
55 |
Correct |
5 ms |
1228 KB |
answer = YES |
56 |
Correct |
10 ms |
2252 KB |
answer = YES |
57 |
Correct |
10 ms |
2244 KB |
answer = YES |
58 |
Correct |
8 ms |
2124 KB |
answer = YES |
59 |
Correct |
8 ms |
2124 KB |
answer = YES |
60 |
Correct |
9 ms |
2324 KB |
answer = YES |
61 |
Correct |
7 ms |
1356 KB |
answer = YES |
62 |
Correct |
49 ms |
8308 KB |
answer = NO |
63 |
Correct |
70 ms |
12228 KB |
answer = YES |
64 |
Correct |
74 ms |
12324 KB |
answer = NO |
65 |
Correct |
72 ms |
12284 KB |
answer = YES |
66 |
Correct |
2 ms |
716 KB |
answer = YES |
67 |
Correct |
87 ms |
19684 KB |
answer = YES |
68 |
Correct |
90 ms |
19716 KB |
answer = YES |
69 |
Correct |
83 ms |
19760 KB |
answer = YES |
70 |
Correct |
127 ms |
28164 KB |
answer = YES |
71 |
Correct |
88 ms |
19748 KB |
answer = YES |
72 |
Correct |
145 ms |
20392 KB |
answer = YES |
73 |
Correct |
115 ms |
20352 KB |
answer = YES |
74 |
Correct |
64 ms |
12864 KB |
answer = YES |
75 |
Correct |
41 ms |
12740 KB |
answer = NO |
76 |
Correct |
12 ms |
2764 KB |
answer = YES |
77 |
Correct |
24 ms |
5224 KB |
answer = YES |
78 |
Correct |
45 ms |
8928 KB |
answer = YES |
79 |
Correct |
97 ms |
17516 KB |
answer = YES |
80 |
Correct |
66 ms |
12864 KB |
answer = YES |
81 |
Correct |
60 ms |
18972 KB |
answer = NO |
82 |
Correct |
111 ms |
19740 KB |
answer = YES |
83 |
Correct |
129 ms |
19708 KB |
answer = YES |
84 |
Correct |
122 ms |
19860 KB |
answer = YES |
85 |
Correct |
86 ms |
19736 KB |
answer = YES |
86 |
Correct |
83 ms |
19764 KB |
answer = YES |
87 |
Correct |
77 ms |
19164 KB |
answer = NO |
88 |
Correct |
121 ms |
19584 KB |
answer = YES |
89 |
Correct |
121 ms |
22700 KB |
answer = YES |
90 |
Correct |
123 ms |
22632 KB |
answer = YES |
91 |
Correct |
134 ms |
22712 KB |
answer = YES |
92 |
Correct |
51 ms |
10372 KB |
answer = YES |
93 |
Correct |
51 ms |
10364 KB |
answer = YES |
94 |
Correct |
68 ms |
19752 KB |
answer = NO |
95 |
Correct |
84 ms |
22288 KB |
answer = NO |
96 |
Correct |
241 ms |
27060 KB |
answer = YES |
97 |
Correct |
44 ms |
19744 KB |
answer = NO |