답안 #938504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938504 2024-03-05T08:27:27 Z Gromp15 Graph (BOI20_graph) C++17
34 / 100
700 ms 1824 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);
		int ans2 = 1e9;
		bool found = 0;
		for (int i = -2*comp_size; i <= 2*comp_size; i++) {
			each[v] = i;
			vector<int> used;
			int sum = 0;
			auto dfs2 = [&](auto&& s, int v) -> void {
				time[v] = timer;
				used.emplace_back(v);
				sum += abs(each[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 && ckmin(ans2, sum)) {
				found = 1;
				for (int x : used) {
					ans[x] = each[x];
				}
			}
		}
		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();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 460 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 344 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 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 344 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 460 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 344 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 460 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 344 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 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 344 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 460 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 344 KB answer = NO
24 Correct 1 ms 460 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 460 KB answer = YES
27 Correct 1 ms 348 KB answer = YES
28 Correct 1 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 1 ms 348 KB answer = NO
31 Correct 1 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 1 ms 600 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 1 ms 348 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 460 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 344 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 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 344 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 460 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 344 KB answer = NO
24 Correct 1 ms 460 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 460 KB answer = YES
27 Correct 1 ms 348 KB answer = YES
28 Correct 1 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 1 ms 348 KB answer = NO
31 Correct 1 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 1 ms 600 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 1 ms 348 KB answer = YES
37 Correct 4 ms 348 KB answer = YES
38 Correct 2 ms 348 KB answer = YES
39 Correct 23 ms 548 KB answer = YES
40 Correct 56 ms 564 KB answer = YES
41 Correct 41 ms 348 KB answer = NO
42 Correct 49 ms 564 KB answer = YES
43 Correct 19 ms 600 KB answer = YES
44 Correct 9 ms 344 KB answer = YES
45 Correct 20 ms 560 KB answer = YES
46 Correct 12 ms 528 KB answer = YES
47 Correct 56 ms 568 KB answer = YES
48 Correct 53 ms 568 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 460 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 344 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 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 344 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 460 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 344 KB answer = NO
24 Correct 1 ms 460 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 460 KB answer = YES
27 Correct 1 ms 348 KB answer = YES
28 Correct 1 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 1 ms 348 KB answer = NO
31 Correct 1 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 1 ms 600 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 1 ms 348 KB answer = YES
37 Correct 4 ms 348 KB answer = YES
38 Correct 2 ms 348 KB answer = YES
39 Correct 23 ms 548 KB answer = YES
40 Correct 56 ms 564 KB answer = YES
41 Correct 41 ms 348 KB answer = NO
42 Correct 49 ms 564 KB answer = YES
43 Correct 19 ms 600 KB answer = YES
44 Correct 9 ms 344 KB answer = YES
45 Correct 20 ms 560 KB answer = YES
46 Correct 12 ms 528 KB answer = YES
47 Correct 56 ms 568 KB answer = YES
48 Correct 53 ms 568 KB answer = YES
49 Execution timed out 1051 ms 1824 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 460 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 344 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 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 344 KB answer = YES
16 Correct 1 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 460 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 344 KB answer = NO
24 Correct 1 ms 460 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 1 ms 460 KB answer = YES
27 Correct 1 ms 348 KB answer = YES
28 Correct 1 ms 348 KB answer = YES
29 Correct 1 ms 348 KB answer = YES
30 Correct 1 ms 348 KB answer = NO
31 Correct 1 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 1 ms 600 KB answer = YES
34 Correct 1 ms 348 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 1 ms 348 KB answer = YES
37 Correct 4 ms 348 KB answer = YES
38 Correct 2 ms 348 KB answer = YES
39 Correct 23 ms 548 KB answer = YES
40 Correct 56 ms 564 KB answer = YES
41 Correct 41 ms 348 KB answer = NO
42 Correct 49 ms 564 KB answer = YES
43 Correct 19 ms 600 KB answer = YES
44 Correct 9 ms 344 KB answer = YES
45 Correct 20 ms 560 KB answer = YES
46 Correct 12 ms 528 KB answer = YES
47 Correct 56 ms 568 KB answer = YES
48 Correct 53 ms 568 KB answer = YES
49 Execution timed out 1051 ms 1824 KB Time limit exceeded
50 Halted 0 ms 0 KB -