Submission #938603

# Submission time Handle Problem Language Result Execution time Memory
938603 2024-03-05T11:02:27 Z Gromp15 Graph (BOI20_graph) C++17
34 / 100
310 ms 2640 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
	int n, m;
	cin >> n >> m;
	vector<vector<ar<int, 2>>> adj(n+1);
	vector<ar<int, 3>> E;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		E.push_back({x, y, w});
		adj[x].push_back({y, 2*w});
		adj[y].push_back({x, 2*w});
	}
	vector<int> ans(n+1);
	vector<bool> vis2(n+1);
	vector<int> depth(n+1), val(n+1);
	for (int v = 1; v <= n; v++) if (!vis2[v]) {
		ll tot_sum = 0;
		vector<ar<int, 3>> edges;
		vector<int> comp;
		auto dfs = [&](auto&& s, int v, int cur) -> void {
			vis2[v] = 1;
			comp.emplace_back(v);
			val[v] = cur;
			tot_sum += cur;
			for (auto [u, w] : adj[v]) {
				edges.push_back({v, u, w});
				if (!vis2[u]) {
					depth[u] = depth[v] + 1;
					s(s, u, w - cur);
				}
			}
		};
		dfs(dfs, v, 0);
		// tot_sum + totx = final val
		int need; bool f = 1;
		for (auto [x, y, w] : edges) {
			if ((depth[x] + depth[y]) & 1) { // they must have the same val
				if (val[x] + val[y] != w) {
					cout << "NO\n"; return;
				}
			}
			else {
				// val[x] + val[y] +/- 2x = w
				int other = (w - val[x] - val[y]) * (depth[x] & 1 ? -1 : 1);
				assert(other % 2 == 0);
				other /= 2;
				if (f) {
					need = other, f = 0;
				}
				else {
					if (need != other) {
						cout << "NO\n"; return;
					}
				}
			}
		}
		if (f) {
			// choose x that minimizes tot_sum + tot*x
			ll best = 1e18; int who = -1;
			for (int i = -sz(comp); i <= sz(comp); i++) {
				ll sum = 0;
				for (int u : comp) {
					sum += abs(val[u] + i * (depth[u] & 1 ? -1 : 1));
				}
				if (ckmin(best, sum)) who = i;
			}
			for (int u : comp) {
				ans[u] = val[u] + who * (depth[u] & 1 ? -1 : 1);
			}
		}
		else {
			// x is set
			for (int u : comp) {
				ans[u] = val[u] + need * (depth[u] & 1 ? -1 : 1);
			}
		}
	}
	cout << "YES\n";
	cout << fixed << setprecision(1);

	for (int i = 1; i <= n; i++) cout << (db)ans[i] / 2 << " \n"[i==n];



}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 456 KB answer = YES
14 Correct 1 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 348 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 456 KB answer = YES
14 Correct 1 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 348 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 1 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 500 KB answer = YES
32 Correct 0 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 0 ms 348 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 456 KB answer = YES
14 Correct 1 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 348 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 1 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 500 KB answer = YES
32 Correct 0 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 0 ms 348 KB answer = YES
37 Correct 1 ms 344 KB answer = YES
38 Correct 0 ms 348 KB answer = YES
39 Correct 1 ms 348 KB answer = YES
40 Correct 1 ms 604 KB answer = YES
41 Correct 1 ms 604 KB answer = NO
42 Correct 3 ms 604 KB answer = YES
43 Correct 2 ms 348 KB answer = YES
44 Correct 1 ms 348 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 1 ms 604 KB answer = YES
48 Correct 1 ms 604 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 456 KB answer = YES
14 Correct 1 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 348 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 1 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 500 KB answer = YES
32 Correct 0 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 0 ms 348 KB answer = YES
37 Correct 1 ms 344 KB answer = YES
38 Correct 0 ms 348 KB answer = YES
39 Correct 1 ms 348 KB answer = YES
40 Correct 1 ms 604 KB answer = YES
41 Correct 1 ms 604 KB answer = NO
42 Correct 3 ms 604 KB answer = YES
43 Correct 2 ms 348 KB answer = YES
44 Correct 1 ms 348 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 1 ms 604 KB answer = YES
48 Correct 1 ms 604 KB answer = YES
49 Correct 310 ms 1884 KB answer = YES
50 Correct 7 ms 2440 KB answer = YES
51 Correct 304 ms 2640 KB answer = YES
52 Correct 4 ms 2640 KB answer = NO
53 Correct 4 ms 604 KB answer = YES
54 Correct 15 ms 600 KB answer = YES
55 Correct 87 ms 1512 KB answer = YES
56 Correct 288 ms 1876 KB answer = YES
57 Incorrect 46 ms 1560 KB participant answer is larger than the answer of jury
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 456 KB answer = YES
14 Correct 1 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 348 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 1 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 500 KB answer = YES
32 Correct 0 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 0 ms 348 KB answer = YES
37 Correct 1 ms 344 KB answer = YES
38 Correct 0 ms 348 KB answer = YES
39 Correct 1 ms 348 KB answer = YES
40 Correct 1 ms 604 KB answer = YES
41 Correct 1 ms 604 KB answer = NO
42 Correct 3 ms 604 KB answer = YES
43 Correct 2 ms 348 KB answer = YES
44 Correct 1 ms 348 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 1 ms 604 KB answer = YES
48 Correct 1 ms 604 KB answer = YES
49 Correct 310 ms 1884 KB answer = YES
50 Correct 7 ms 2440 KB answer = YES
51 Correct 304 ms 2640 KB answer = YES
52 Correct 4 ms 2640 KB answer = NO
53 Correct 4 ms 604 KB answer = YES
54 Correct 15 ms 600 KB answer = YES
55 Correct 87 ms 1512 KB answer = YES
56 Correct 288 ms 1876 KB answer = YES
57 Incorrect 46 ms 1560 KB participant answer is larger than the answer of jury
58 Halted 0 ms 0 KB -