Submission #569390

# Submission time Handle Problem Language Result Execution time Memory
569390 2022-05-27T11:08:21 Z nonsensenonsense1 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
787 ms 27540 KB
#include <cstdio>
#include <vector>
#include <algorithm>

const int N = 500;
const int M = 100000;
int n, m, q;
std::pair<int, std::pair<int, int> > a[M];
std::vector<std::pair<int, int> > g[N];

int dfs(int v, int to, int pr = -1) {
	if (v == to) return ~(1 << 31);
	for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i].first != pr) {
		int k = dfs(g[v][i].first, to, v);
		if (k != (1 << 31)) return std::min(k, g[v][i].second);
	}
	return 1 << 31;
}

void rm(int u, int v) {
	for (int t = 0; t < 2; ++t) {
		int i;
		for (i = 0; g[u][i].first != v; ++i);
		g[u].erase(g[u].begin() + i);
		std::swap(u, v);
	}
}

void add(int u, int v, int i) {
	for (int t = 0; t < 2; ++t) {
		g[u].push_back(std::make_pair(v, i));
		std::swap(u, v);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &a[i].second.first, &a[i].second.second, &a[i].first);
		--a[i].second.first;
		--a[i].second.second;
	}
	std::sort(a, a + m);
	std::vector<std::pair<int, std::pair<int, int> > > upd;
	for (int i = 0; i < m; ++i) {
		int e = dfs(a[i].second.first, a[i].second.second);
		if (e == (1 << 31)) upd.push_back({0, {-1, a[i].first}});
		else {
			upd.push_back({a[i].first + a[e].first + 1 >> 1, {-2, a[i].first + a[e].first}});
			rm(a[e].second.first, a[e].second.second);
		}
		add(a[i].second.first, a[i].second.second, i);
		upd.push_back({a[i].first, {2, -2 * a[i].first}});
	}
	std::sort(upd.begin(), upd.end());
	scanf("%d", &q);
	int k = 0;
	long long b = 0;
	for (int i = 0; q; --q) {
		int x;
		scanf("%d", &x);
		while (i < (int)upd.size() && upd[i].first <= x) {
			k += upd[i].second.first;
			b += upd[i].second.second;
			++i;
		}
		printf("%lld\n", (long long)k * x + b);
	}
	return 0;
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:49:43: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |    upd.push_back({a[i].first + a[e].first + 1 >> 1, {-2, a[i].first + a[e].first}});
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~^~~
reconstruction.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
reconstruction.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%d%d%d", &a[i].second.first, &a[i].second.second, &a[i].first);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
reconstruction.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 473 ms 6316 KB Output is correct
21 Correct 217 ms 6296 KB Output is correct
22 Correct 329 ms 6232 KB Output is correct
23 Correct 337 ms 6368 KB Output is correct
24 Correct 318 ms 6176 KB Output is correct
25 Correct 405 ms 6232 KB Output is correct
26 Correct 409 ms 6420 KB Output is correct
27 Correct 405 ms 6368 KB Output is correct
28 Correct 416 ms 6384 KB Output is correct
29 Correct 223 ms 6388 KB Output is correct
30 Correct 378 ms 6360 KB Output is correct
31 Correct 413 ms 6420 KB Output is correct
32 Correct 368 ms 6348 KB Output is correct
33 Correct 377 ms 6300 KB Output is correct
34 Correct 155 ms 6980 KB Output is correct
35 Correct 357 ms 6312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 434 ms 26280 KB Output is correct
5 Correct 432 ms 25588 KB Output is correct
6 Correct 423 ms 25476 KB Output is correct
7 Correct 397 ms 27400 KB Output is correct
8 Correct 329 ms 27496 KB Output is correct
9 Correct 347 ms 27540 KB Output is correct
10 Correct 464 ms 25520 KB Output is correct
11 Correct 320 ms 27532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 291 ms 21952 KB Output is correct
21 Correct 279 ms 22048 KB Output is correct
22 Correct 268 ms 22300 KB Output is correct
23 Correct 255 ms 22184 KB Output is correct
24 Correct 255 ms 22152 KB Output is correct
25 Correct 263 ms 22312 KB Output is correct
26 Correct 268 ms 22208 KB Output is correct
27 Correct 294 ms 22240 KB Output is correct
28 Correct 288 ms 22192 KB Output is correct
29 Correct 245 ms 22312 KB Output is correct
30 Correct 256 ms 22276 KB Output is correct
31 Correct 268 ms 22020 KB Output is correct
32 Correct 267 ms 22604 KB Output is correct
33 Correct 274 ms 22080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 473 ms 6316 KB Output is correct
21 Correct 217 ms 6296 KB Output is correct
22 Correct 329 ms 6232 KB Output is correct
23 Correct 337 ms 6368 KB Output is correct
24 Correct 318 ms 6176 KB Output is correct
25 Correct 405 ms 6232 KB Output is correct
26 Correct 409 ms 6420 KB Output is correct
27 Correct 405 ms 6368 KB Output is correct
28 Correct 416 ms 6384 KB Output is correct
29 Correct 223 ms 6388 KB Output is correct
30 Correct 378 ms 6360 KB Output is correct
31 Correct 413 ms 6420 KB Output is correct
32 Correct 368 ms 6348 KB Output is correct
33 Correct 377 ms 6300 KB Output is correct
34 Correct 155 ms 6980 KB Output is correct
35 Correct 357 ms 6312 KB Output is correct
36 Correct 361 ms 6496 KB Output is correct
37 Correct 221 ms 6572 KB Output is correct
38 Correct 322 ms 6600 KB Output is correct
39 Correct 338 ms 6424 KB Output is correct
40 Correct 332 ms 6076 KB Output is correct
41 Correct 355 ms 6516 KB Output is correct
42 Correct 425 ms 6356 KB Output is correct
43 Correct 416 ms 6608 KB Output is correct
44 Correct 396 ms 6748 KB Output is correct
45 Correct 211 ms 6496 KB Output is correct
46 Correct 399 ms 6600 KB Output is correct
47 Correct 362 ms 6576 KB Output is correct
48 Correct 390 ms 6508 KB Output is correct
49 Correct 356 ms 6592 KB Output is correct
50 Correct 162 ms 7140 KB Output is correct
51 Correct 382 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 473 ms 6316 KB Output is correct
21 Correct 217 ms 6296 KB Output is correct
22 Correct 329 ms 6232 KB Output is correct
23 Correct 337 ms 6368 KB Output is correct
24 Correct 318 ms 6176 KB Output is correct
25 Correct 405 ms 6232 KB Output is correct
26 Correct 409 ms 6420 KB Output is correct
27 Correct 405 ms 6368 KB Output is correct
28 Correct 416 ms 6384 KB Output is correct
29 Correct 223 ms 6388 KB Output is correct
30 Correct 378 ms 6360 KB Output is correct
31 Correct 413 ms 6420 KB Output is correct
32 Correct 368 ms 6348 KB Output is correct
33 Correct 377 ms 6300 KB Output is correct
34 Correct 155 ms 6980 KB Output is correct
35 Correct 357 ms 6312 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 434 ms 26280 KB Output is correct
40 Correct 432 ms 25588 KB Output is correct
41 Correct 423 ms 25476 KB Output is correct
42 Correct 397 ms 27400 KB Output is correct
43 Correct 329 ms 27496 KB Output is correct
44 Correct 347 ms 27540 KB Output is correct
45 Correct 464 ms 25520 KB Output is correct
46 Correct 320 ms 27532 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 291 ms 21952 KB Output is correct
49 Correct 279 ms 22048 KB Output is correct
50 Correct 268 ms 22300 KB Output is correct
51 Correct 255 ms 22184 KB Output is correct
52 Correct 255 ms 22152 KB Output is correct
53 Correct 263 ms 22312 KB Output is correct
54 Correct 268 ms 22208 KB Output is correct
55 Correct 294 ms 22240 KB Output is correct
56 Correct 288 ms 22192 KB Output is correct
57 Correct 245 ms 22312 KB Output is correct
58 Correct 256 ms 22276 KB Output is correct
59 Correct 268 ms 22020 KB Output is correct
60 Correct 267 ms 22604 KB Output is correct
61 Correct 274 ms 22080 KB Output is correct
62 Correct 361 ms 6496 KB Output is correct
63 Correct 221 ms 6572 KB Output is correct
64 Correct 322 ms 6600 KB Output is correct
65 Correct 338 ms 6424 KB Output is correct
66 Correct 332 ms 6076 KB Output is correct
67 Correct 355 ms 6516 KB Output is correct
68 Correct 425 ms 6356 KB Output is correct
69 Correct 416 ms 6608 KB Output is correct
70 Correct 396 ms 6748 KB Output is correct
71 Correct 211 ms 6496 KB Output is correct
72 Correct 399 ms 6600 KB Output is correct
73 Correct 362 ms 6576 KB Output is correct
74 Correct 390 ms 6508 KB Output is correct
75 Correct 356 ms 6592 KB Output is correct
76 Correct 162 ms 7140 KB Output is correct
77 Correct 382 ms 6272 KB Output is correct
78 Correct 644 ms 25044 KB Output is correct
79 Correct 514 ms 26916 KB Output is correct
80 Correct 622 ms 26244 KB Output is correct
81 Correct 611 ms 26292 KB Output is correct
82 Correct 590 ms 25260 KB Output is correct
83 Correct 787 ms 24800 KB Output is correct
84 Correct 766 ms 22308 KB Output is correct
85 Correct 744 ms 25124 KB Output is correct
86 Correct 688 ms 14056 KB Output is correct
87 Correct 476 ms 19972 KB Output is correct
88 Correct 626 ms 25076 KB Output is correct
89 Correct 661 ms 25112 KB Output is correct
90 Correct 651 ms 25112 KB Output is correct
91 Correct 639 ms 17840 KB Output is correct
92 Correct 434 ms 17796 KB Output is correct
93 Correct 606 ms 18296 KB Output is correct