Submission #938503

# Submission time Handle Problem Language Result Execution time Memory
938503 2024-03-05T08:26:08 Z Gromp15 Graph (BOI20_graph) C++17
0 / 100
0 ms 348 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);
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> 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> each(n+1), time(n+1);
	int timer = 1;
	for (int v = 1; v <= n; v++) if (!vis2[v]) {
		int comp_size = 0;
		vector<ar<int, 3>> edges;
		auto dfs = [&](auto&& s, int v) -> void {
			comp_size++, vis2[v] = 1;
			for (auto [u, w] : adj[v]) {
				if (!vis2[u]) s(s, u);
				edges.push_back({v, u, w});
			}
		};
		dfs(dfs, v);
		bool found = 0;
		for (int i = -2*comp_size; i <= 2*comp_size; i++) {
			each[v] = i;
			vector<int> used;
			auto dfs2 = [&](auto&& s, int v) -> void {
				time[v] = timer;
				used.emplace_back(v);
				for (auto [u, w] : adj[v]) if (time[u] != timer) {
					each[u] = w - each[v];
					s(s, u);
				}
			};
			dfs2(dfs2, v);
			timer++;
			bool ok = 1;
			for (auto [x, y, w] : edges) {
				if (each[x] + each[y] != w) {
					ok = 0;
					break;
				}
			}
			if (ok) {
				found = 1;
				for (int x : used) {
					ans[x] = each[x];
				}
				break;
			}
		}
		if (!found) {
			cout << "NO\n";
			return;
		}
	}
	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 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -