Submission #917375

# Submission time Handle Problem Language Result Execution time Memory
917375 2024-01-28T03:40:50 Z NK_ Graph (BOI20_graph) C++17
100 / 100
183 ms 38092 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using db = long double;
 
const int INF = 1e9;
const int B = 1e8;
const db EPS = 1e-9;
 
int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M; cin >> N >> M;
 
	V<vpi> adj(N); for(int i = 0; i < M; i++) {
		int u, v, w; cin >> u >> v >> w; --u, --v;
		adj[u].pb(mp(v, w));
		adj[v].pb(mp(u, w));
	}
 
 
	auto C = [&](pi p, int w) {
		// cout << p.f << " " << p.s << " " << w << endl;
		return mp(w - p.f, -p.s);
	};
 
	cout << fixed << setprecision(10);
 
	vi vis(N), COMP; V<set<pi>> S(N);
	function<void(int)> dfs = [&](int u) {
		vis[u] = 1; COMP.pb(u);
		pi p = *begin(S[u]);
		// cout << u << " => " << p.f << " " << p.s << endl;
		for(auto& e : adj[u]) {
			int v, w; tie(v, w) = e;
			// cout << v << " " << w << endl;
 
			S[v].insert(C(p, w));
			if (!vis[v]) dfs(v);
		}
	};
 
	V<db> ans(N, INF); 
	function<void(int)> get = [&](int u) {
		// cout << u << endl;
		for(auto& e : adj[u]) {
			int v, w; tie(v, w) = e;
			// cout << u << " => " << v << endl;
			// cout << ans[u] << " -> " << ans[v] << endl;
			db x = w - ans[u];
			if (ans[v] > B) {
				ans[v] = x; get(v);
			} else {
				if (abs(ans[v] - x) > EPS) {
					cout << "NO" << nl;
					exit(0-0);
				}
			}	
		}
	};
 
	for(int r = 0; r < N; r++) if (!vis[r]) {
		COMP = {}; S[r].insert(mp(0, 1)); dfs(r);
		// cout << endl << endl;
 
		db x = INF; int R = -1; vi roots;
		for(auto& i : COMP) {
			if (sz(S[i]) >= 2) {
				// cout << i << endl;
				vi pos, neg; for(auto& p : S[i]) {
					// cout << p.f << " " << p.s << endl;
					if (p.s == -1) neg.pb(p.f);
					else pos.pb(p.f);
				}
	 
				if (max(sz(pos), sz(neg)) > 1) {
					cout << "NO" << nl;
					exit(0-0);
				}
	 
				x = db(pos.back() + neg.back()) / db(2);
				// cout << x << endl;
				R = i;
				// cout << "DONE" << endl;
				break;
			} else {
				pi p = *begin(S[i]);
				roots.pb(p.f * p.s * -1);
			}
		}

		if (R == -1) {
			sort(begin(roots), end(roots));
			// for(auto& c : roots) cout << c << " ";
			// cout << endl;
			R = r; x = roots[sz(roots) / 2];
		}
 
		ans[R] = x; get(R);
	}
 
	cout << "YES" << nl;
	for(auto& x : ans) cout << x << " ";
	cout << nl;
	
	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 1 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 1 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 344 KB answer = NO
10 Correct 1 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 1 ms 348 KB answer = YES
15 Correct 1 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 1 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 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 1 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 1 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 344 KB answer = NO
10 Correct 1 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 1 ms 348 KB answer = YES
15 Correct 1 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 1 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 0 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 0 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 0 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 0 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 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 1 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 1 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 344 KB answer = NO
10 Correct 1 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 1 ms 348 KB answer = YES
15 Correct 1 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 1 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 0 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 0 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 0 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 0 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 348 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 1 ms 604 KB answer = YES
43 Correct 1 ms 604 KB answer = YES
44 Correct 2 ms 604 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 2 ms 604 KB answer = YES
48 Correct 2 ms 604 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 1 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 1 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 344 KB answer = NO
10 Correct 1 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 1 ms 348 KB answer = YES
15 Correct 1 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 1 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 0 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 0 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 0 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 0 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 348 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 1 ms 604 KB answer = YES
43 Correct 1 ms 604 KB answer = YES
44 Correct 2 ms 604 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 2 ms 604 KB answer = YES
48 Correct 2 ms 604 KB answer = YES
49 Correct 10 ms 2392 KB answer = YES
50 Correct 8 ms 2908 KB answer = YES
51 Correct 9 ms 2904 KB answer = YES
52 Correct 5 ms 2652 KB answer = NO
53 Correct 1 ms 604 KB answer = YES
54 Correct 2 ms 860 KB answer = YES
55 Correct 5 ms 1372 KB answer = YES
56 Correct 8 ms 2396 KB answer = YES
57 Correct 8 ms 2396 KB answer = YES
58 Correct 8 ms 2140 KB answer = YES
59 Correct 7 ms 2220 KB answer = YES
60 Correct 8 ms 2428 KB answer = YES
61 Correct 4 ms 1372 KB answer = YES
62 Correct 109 ms 24064 KB answer = NO
63 Correct 59 ms 9336 KB answer = YES
64 Correct 47 ms 9172 KB answer = NO
65 Correct 54 ms 9300 KB answer = YES
66 Correct 2 ms 860 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 1 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 1 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 344 KB answer = NO
10 Correct 1 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 1 ms 348 KB answer = YES
15 Correct 1 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 1 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 1 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 0 ms 348 KB answer = YES
25 Correct 0 ms 348 KB answer = YES
26 Correct 0 ms 348 KB answer = YES
27 Correct 0 ms 348 KB answer = YES
28 Correct 0 ms 348 KB answer = YES
29 Correct 0 ms 348 KB answer = YES
30 Correct 0 ms 348 KB answer = NO
31 Correct 0 ms 348 KB answer = YES
32 Correct 1 ms 348 KB answer = YES
33 Correct 0 ms 348 KB answer = YES
34 Correct 0 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 348 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 1 ms 604 KB answer = YES
43 Correct 1 ms 604 KB answer = YES
44 Correct 2 ms 604 KB answer = YES
45 Correct 1 ms 604 KB answer = YES
46 Correct 1 ms 348 KB answer = YES
47 Correct 2 ms 604 KB answer = YES
48 Correct 2 ms 604 KB answer = YES
49 Correct 10 ms 2392 KB answer = YES
50 Correct 8 ms 2908 KB answer = YES
51 Correct 9 ms 2904 KB answer = YES
52 Correct 5 ms 2652 KB answer = NO
53 Correct 1 ms 604 KB answer = YES
54 Correct 2 ms 860 KB answer = YES
55 Correct 5 ms 1372 KB answer = YES
56 Correct 8 ms 2396 KB answer = YES
57 Correct 8 ms 2396 KB answer = YES
58 Correct 8 ms 2140 KB answer = YES
59 Correct 7 ms 2220 KB answer = YES
60 Correct 8 ms 2428 KB answer = YES
61 Correct 4 ms 1372 KB answer = YES
62 Correct 109 ms 24064 KB answer = NO
63 Correct 59 ms 9336 KB answer = YES
64 Correct 47 ms 9172 KB answer = NO
65 Correct 54 ms 9300 KB answer = YES
66 Correct 2 ms 860 KB answer = YES
67 Correct 89 ms 31388 KB answer = YES
68 Correct 79 ms 31260 KB answer = YES
69 Correct 76 ms 31176 KB answer = YES
70 Correct 107 ms 38092 KB answer = YES
71 Correct 79 ms 31184 KB answer = YES
72 Correct 105 ms 20932 KB answer = YES
73 Correct 81 ms 20940 KB answer = YES
74 Correct 63 ms 19052 KB answer = YES
75 Correct 30 ms 18380 KB answer = NO
76 Correct 10 ms 2908 KB answer = YES
77 Correct 20 ms 5512 KB answer = YES
78 Correct 35 ms 9256 KB answer = YES
79 Correct 74 ms 17916 KB answer = YES
80 Correct 63 ms 19224 KB answer = YES
81 Correct 51 ms 24524 KB answer = NO
82 Correct 107 ms 30408 KB answer = YES
83 Correct 125 ms 31248 KB answer = YES
84 Correct 117 ms 31428 KB answer = YES
85 Correct 89 ms 31432 KB answer = YES
86 Correct 88 ms 31356 KB answer = YES
87 Correct 44 ms 19024 KB answer = NO
88 Correct 149 ms 24828 KB answer = YES
89 Correct 87 ms 21656 KB answer = YES
90 Correct 81 ms 21584 KB answer = YES
91 Correct 112 ms 21572 KB answer = YES
92 Correct 39 ms 10704 KB answer = YES
93 Correct 39 ms 10712 KB answer = YES
94 Correct 78 ms 29760 KB answer = NO
95 Correct 29 ms 14676 KB answer = NO
96 Correct 183 ms 33740 KB answer = YES
97 Correct 41 ms 29896 KB answer = NO