답안 #596821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596821 2022-07-15T07:01:04 Z cheissmart Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
2508 ms 20960 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7;

struct DSU {
	int n;
	vi p, sz;
	DSU(int _n) {
		n = _n;
		p = vi(n), sz = vi(n, 1);
		iota(ALL(p), 0);
	}
	int find(int u) {
		return p[u] == u ? u : p[u] = find(p[u]);
	}
	void unite(int u, int v) {
		u = find(u), v = find(v);
		assert(u != v);
		if(sz[u] > sz[v]) swap(u, v);
		p[u] = v;
		sz[v] += sz[u];
	}
};

signed main()
{
	IO_OP;

	int n, m;
	cin >> n >> m;
	V<array<int, 3>> es;
	for(int i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w, u--, v--;
		es.PB({u, v, w});
	}
	sort(ALL(es), [&] (array<int, 3> a, array<int, 3> b) {
		return a[2] < b[2];
	});

	V<array<int, 3>> ev;

	for(int _ = 0; _ < 2; _++) {
		V<array<int, 3>> tree;
		for(int i = 0; i < m; i++) {
			reverse(ALL(tree));
			tree.PB(es[i]);
			V<array<int, 3>> ntree;
			DSU dsu(n);
			array<int, 3> bye = {-1, -1, -1};	
			for(int j = SZ(tree) - 1; j >= 0; j--) {
				auto[u, v, w] = tree[j];
				if(dsu.find(u) == dsu.find(v)) {
					bye = tree[j];
				} else {
					ntree.PB(tree[j]);
					dsu.unite(u, v);
				}
			}
			if(bye[0] != -1) {
				if(_ == 0) {
					int mid = bye[2] + es[i][2];
					ev.PB({mid + 1, es[i][2], _});
					ev.PB({es[i][2] * 2 + 1, -es[i][2], -_});
				} else {
					int mid = bye[2] + es[i][2];
					ev.PB({es[i][2] * 2 + 1, -es[i][2], _});
					ev.PB({mid + 1, es[i][2], -_});
				}
			} else {
				if(_ == 0) {
					ev.PB({0, es[i][2], _});
					ev.PB({es[i][2] * 2 + 1, -es[i][2], -_});
				} else {
					ev.PB({es[i][2] * 2 + 1, -es[i][2], _});
				}
			}
			tree = ntree;
		}
		reverse(ALL(es));
	}

	sort(ALL(ev));

	int q;
	cin >> q;
	ll sum = 0, cnt = 0;
	for(int i = 0, j = 0; i < q; i++) {
		int x;
		cin >> x;
		while(j < SZ(ev) && ev[j][0] <= x * 2) {
			cnt += ev[j][2], sum += ev[j++][1];
		}
		cout << sum + 1LL * x * cnt - 1LL * x * (n - 1 - cnt) << '\n';
	}

}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:80:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |     auto[u, v, w] = tree[j];
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2436 ms 8848 KB Output is correct
21 Correct 2060 ms 8868 KB Output is correct
22 Correct 2157 ms 8888 KB Output is correct
23 Correct 2166 ms 9020 KB Output is correct
24 Correct 2327 ms 8896 KB Output is correct
25 Correct 2386 ms 8768 KB Output is correct
26 Correct 2416 ms 8724 KB Output is correct
27 Correct 2414 ms 8816 KB Output is correct
28 Correct 2393 ms 8824 KB Output is correct
29 Correct 2324 ms 8740 KB Output is correct
30 Correct 2384 ms 8868 KB Output is correct
31 Correct 2368 ms 8840 KB Output is correct
32 Correct 2322 ms 8796 KB Output is correct
33 Correct 2335 ms 8772 KB Output is correct
34 Correct 2303 ms 8772 KB Output is correct
35 Correct 2329 ms 8716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2340 ms 19736 KB Output is correct
5 Correct 2318 ms 18824 KB Output is correct
6 Correct 2337 ms 18980 KB Output is correct
7 Correct 1412 ms 20736 KB Output is correct
8 Correct 1249 ms 20928 KB Output is correct
9 Correct 1230 ms 20888 KB Output is correct
10 Correct 2307 ms 18880 KB Output is correct
11 Correct 1256 ms 20960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 192 ms 13780 KB Output is correct
21 Correct 193 ms 15144 KB Output is correct
22 Correct 198 ms 15120 KB Output is correct
23 Correct 191 ms 15176 KB Output is correct
24 Correct 194 ms 15144 KB Output is correct
25 Correct 193 ms 15108 KB Output is correct
26 Correct 193 ms 15032 KB Output is correct
27 Correct 190 ms 15088 KB Output is correct
28 Correct 221 ms 15084 KB Output is correct
29 Correct 197 ms 15052 KB Output is correct
30 Correct 192 ms 15084 KB Output is correct
31 Correct 199 ms 15044 KB Output is correct
32 Correct 198 ms 15848 KB Output is correct
33 Correct 189 ms 14836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2436 ms 8848 KB Output is correct
21 Correct 2060 ms 8868 KB Output is correct
22 Correct 2157 ms 8888 KB Output is correct
23 Correct 2166 ms 9020 KB Output is correct
24 Correct 2327 ms 8896 KB Output is correct
25 Correct 2386 ms 8768 KB Output is correct
26 Correct 2416 ms 8724 KB Output is correct
27 Correct 2414 ms 8816 KB Output is correct
28 Correct 2393 ms 8824 KB Output is correct
29 Correct 2324 ms 8740 KB Output is correct
30 Correct 2384 ms 8868 KB Output is correct
31 Correct 2368 ms 8840 KB Output is correct
32 Correct 2322 ms 8796 KB Output is correct
33 Correct 2335 ms 8772 KB Output is correct
34 Correct 2303 ms 8772 KB Output is correct
35 Correct 2329 ms 8716 KB Output is correct
36 Correct 2321 ms 8564 KB Output is correct
37 Correct 1970 ms 8696 KB Output is correct
38 Correct 2074 ms 8588 KB Output is correct
39 Correct 2122 ms 8500 KB Output is correct
40 Correct 2247 ms 8572 KB Output is correct
41 Correct 2309 ms 8480 KB Output is correct
42 Correct 2321 ms 8580 KB Output is correct
43 Correct 2336 ms 8564 KB Output is correct
44 Correct 2342 ms 8680 KB Output is correct
45 Correct 2333 ms 8580 KB Output is correct
46 Correct 2352 ms 8372 KB Output is correct
47 Correct 2351 ms 8568 KB Output is correct
48 Correct 2320 ms 8324 KB Output is correct
49 Correct 2339 ms 8380 KB Output is correct
50 Correct 2319 ms 8468 KB Output is correct
51 Correct 2312 ms 8528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2436 ms 8848 KB Output is correct
21 Correct 2060 ms 8868 KB Output is correct
22 Correct 2157 ms 8888 KB Output is correct
23 Correct 2166 ms 9020 KB Output is correct
24 Correct 2327 ms 8896 KB Output is correct
25 Correct 2386 ms 8768 KB Output is correct
26 Correct 2416 ms 8724 KB Output is correct
27 Correct 2414 ms 8816 KB Output is correct
28 Correct 2393 ms 8824 KB Output is correct
29 Correct 2324 ms 8740 KB Output is correct
30 Correct 2384 ms 8868 KB Output is correct
31 Correct 2368 ms 8840 KB Output is correct
32 Correct 2322 ms 8796 KB Output is correct
33 Correct 2335 ms 8772 KB Output is correct
34 Correct 2303 ms 8772 KB Output is correct
35 Correct 2329 ms 8716 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 2340 ms 19736 KB Output is correct
40 Correct 2318 ms 18824 KB Output is correct
41 Correct 2337 ms 18980 KB Output is correct
42 Correct 1412 ms 20736 KB Output is correct
43 Correct 1249 ms 20928 KB Output is correct
44 Correct 1230 ms 20888 KB Output is correct
45 Correct 2307 ms 18880 KB Output is correct
46 Correct 1256 ms 20960 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 192 ms 13780 KB Output is correct
49 Correct 193 ms 15144 KB Output is correct
50 Correct 198 ms 15120 KB Output is correct
51 Correct 191 ms 15176 KB Output is correct
52 Correct 194 ms 15144 KB Output is correct
53 Correct 193 ms 15108 KB Output is correct
54 Correct 193 ms 15032 KB Output is correct
55 Correct 190 ms 15088 KB Output is correct
56 Correct 221 ms 15084 KB Output is correct
57 Correct 197 ms 15052 KB Output is correct
58 Correct 192 ms 15084 KB Output is correct
59 Correct 199 ms 15044 KB Output is correct
60 Correct 198 ms 15848 KB Output is correct
61 Correct 189 ms 14836 KB Output is correct
62 Correct 2321 ms 8564 KB Output is correct
63 Correct 1970 ms 8696 KB Output is correct
64 Correct 2074 ms 8588 KB Output is correct
65 Correct 2122 ms 8500 KB Output is correct
66 Correct 2247 ms 8572 KB Output is correct
67 Correct 2309 ms 8480 KB Output is correct
68 Correct 2321 ms 8580 KB Output is correct
69 Correct 2336 ms 8564 KB Output is correct
70 Correct 2342 ms 8680 KB Output is correct
71 Correct 2333 ms 8580 KB Output is correct
72 Correct 2352 ms 8372 KB Output is correct
73 Correct 2351 ms 8568 KB Output is correct
74 Correct 2320 ms 8324 KB Output is correct
75 Correct 2339 ms 8380 KB Output is correct
76 Correct 2319 ms 8468 KB Output is correct
77 Correct 2312 ms 8528 KB Output is correct
78 Correct 2486 ms 17528 KB Output is correct
79 Correct 2094 ms 19568 KB Output is correct
80 Correct 2237 ms 18496 KB Output is correct
81 Correct 2329 ms 18516 KB Output is correct
82 Correct 2373 ms 17580 KB Output is correct
83 Correct 2483 ms 17536 KB Output is correct
84 Correct 2479 ms 17424 KB Output is correct
85 Correct 2465 ms 17544 KB Output is correct
86 Correct 2471 ms 17376 KB Output is correct
87 Correct 2474 ms 19156 KB Output is correct
88 Correct 2499 ms 17676 KB Output is correct
89 Correct 2483 ms 17676 KB Output is correct
90 Correct 2508 ms 17532 KB Output is correct
91 Correct 2487 ms 17588 KB Output is correct
92 Correct 2496 ms 20444 KB Output is correct
93 Correct 2499 ms 18504 KB Output is correct