답안 #748571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748571 2023-05-26T13:36:26 Z AdamGS Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
724 ms 74456 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=1e5+7;
vector<pair<int,pair<ll,ll>>>V[LIM];
pair<ll,pair<int,int>>kraw[LIM];
pair<ll,ll>pr[LIM];
vector<pair<ll,pair<ll,ll>>>P;
ll ans[10*LIM];
pair<ll,ll>DFS(int x, int o, int p) {
	if(x==p) return {INF, INF};
	for(auto i : V[x]) if(i.st!=o) {
		pair<ll,ll>a=DFS(i.st, x, p);
		if(a.st!=-1) return min(a, i.nd);
	}
	return {-1, -1};
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		cin >> kraw[i].nd.st >> kraw[i].nd.nd >> kraw[i].st;
		--kraw[i].nd.st; --kraw[i].nd.nd;
		pr[i].nd=INF;
	}
	sort(kraw, kraw+m);
	rep(i, m) {
		pair<ll,ll>a=DFS(kraw[i].nd.st, kraw[i].nd.st, kraw[i].nd.nd);
		if(a.nd!=-1) {
			pr[a.nd].nd=(kraw[a.nd].st+kraw[i].st+1)/2;
			pr[i].st=(kraw[a.nd].st+kraw[i].st+1)/2;
			vector<pair<int,pair<ll,ll>>>tmp;
			for(auto i : V[kraw[a.nd].nd.st]) if(i.nd.nd!=a.nd) tmp.pb(i);
			V[kraw[a.nd].nd.st]=tmp;
			tmp.clear();
			for(auto i : V[kraw[a.nd].nd.nd]) if(i.nd.nd!=a.nd) tmp.pb(i);
			V[kraw[a.nd].nd.nd]=tmp;
		}
		V[kraw[i].nd.st].pb({kraw[i].nd.nd, {kraw[i].st, i}});
		V[kraw[i].nd.nd].pb({kraw[i].nd.st, {kraw[i].st, i}});
	}
	rep(i, m) {
		P.pb({pr[i].st, {-1, kraw[i].st}});
		P.pb({kraw[i].st, {1, -kraw[i].st}});
		P.pb({kraw[i].st, {1, -kraw[i].st}});
		P.pb({pr[i].nd, {-1, kraw[i].st}});
	}
	int q;
	cin >> q;
	rep(i, q) {
		ll x;
		cin >> x;
		P.pb({x, {2, i}});
	}
	sort(all(P));
	ll ilex=0, ileconst=0;
	for(auto i : P) {
		if(i.nd.st==2) ans[i.nd.nd]=ilex*i.st+ileconst;
		else {
			ilex+=i.nd.st;
			ileconst+=i.nd.nd;
		}
	}
	rep(i, q) cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2692 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2692 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2692 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 422 ms 20036 KB Output is correct
21 Correct 254 ms 20100 KB Output is correct
22 Correct 372 ms 19992 KB Output is correct
23 Correct 367 ms 20124 KB Output is correct
24 Correct 347 ms 20040 KB Output is correct
25 Correct 440 ms 19996 KB Output is correct
26 Correct 407 ms 20232 KB Output is correct
27 Correct 428 ms 20044 KB Output is correct
28 Correct 445 ms 20076 KB Output is correct
29 Correct 272 ms 20456 KB Output is correct
30 Correct 442 ms 20056 KB Output is correct
31 Correct 435 ms 20024 KB Output is correct
32 Correct 442 ms 20128 KB Output is correct
33 Correct 437 ms 20032 KB Output is correct
34 Correct 297 ms 23408 KB Output is correct
35 Correct 433 ms 20016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 543 ms 69064 KB Output is correct
5 Correct 513 ms 69112 KB Output is correct
6 Correct 527 ms 69272 KB Output is correct
7 Correct 395 ms 70960 KB Output is correct
8 Correct 399 ms 71128 KB Output is correct
9 Correct 379 ms 71152 KB Output is correct
10 Correct 501 ms 69212 KB Output is correct
11 Correct 338 ms 71156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2692 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2692 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 308 ms 56220 KB Output is correct
21 Correct 311 ms 56292 KB Output is correct
22 Correct 310 ms 56196 KB Output is correct
23 Correct 312 ms 56188 KB Output is correct
24 Correct 332 ms 56192 KB Output is correct
25 Correct 335 ms 56136 KB Output is correct
26 Correct 312 ms 56172 KB Output is correct
27 Correct 292 ms 56248 KB Output is correct
28 Correct 314 ms 56164 KB Output is correct
29 Correct 313 ms 56152 KB Output is correct
30 Correct 308 ms 56452 KB Output is correct
31 Correct 298 ms 56056 KB Output is correct
32 Correct 297 ms 56876 KB Output is correct
33 Correct 303 ms 56144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2692 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2692 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 422 ms 20036 KB Output is correct
21 Correct 254 ms 20100 KB Output is correct
22 Correct 372 ms 19992 KB Output is correct
23 Correct 367 ms 20124 KB Output is correct
24 Correct 347 ms 20040 KB Output is correct
25 Correct 440 ms 19996 KB Output is correct
26 Correct 407 ms 20232 KB Output is correct
27 Correct 428 ms 20044 KB Output is correct
28 Correct 445 ms 20076 KB Output is correct
29 Correct 272 ms 20456 KB Output is correct
30 Correct 442 ms 20056 KB Output is correct
31 Correct 435 ms 20024 KB Output is correct
32 Correct 442 ms 20128 KB Output is correct
33 Correct 437 ms 20032 KB Output is correct
34 Correct 297 ms 23408 KB Output is correct
35 Correct 433 ms 20016 KB Output is correct
36 Correct 427 ms 20240 KB Output is correct
37 Correct 246 ms 20188 KB Output is correct
38 Correct 381 ms 20216 KB Output is correct
39 Correct 378 ms 20224 KB Output is correct
40 Correct 360 ms 20308 KB Output is correct
41 Correct 462 ms 20212 KB Output is correct
42 Correct 429 ms 20232 KB Output is correct
43 Correct 432 ms 20232 KB Output is correct
44 Correct 419 ms 20232 KB Output is correct
45 Correct 279 ms 20652 KB Output is correct
46 Correct 412 ms 20256 KB Output is correct
47 Correct 452 ms 20372 KB Output is correct
48 Correct 409 ms 20196 KB Output is correct
49 Correct 411 ms 20296 KB Output is correct
50 Correct 286 ms 23612 KB Output is correct
51 Correct 430 ms 20416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2692 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2692 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 422 ms 20036 KB Output is correct
21 Correct 254 ms 20100 KB Output is correct
22 Correct 372 ms 19992 KB Output is correct
23 Correct 367 ms 20124 KB Output is correct
24 Correct 347 ms 20040 KB Output is correct
25 Correct 440 ms 19996 KB Output is correct
26 Correct 407 ms 20232 KB Output is correct
27 Correct 428 ms 20044 KB Output is correct
28 Correct 445 ms 20076 KB Output is correct
29 Correct 272 ms 20456 KB Output is correct
30 Correct 442 ms 20056 KB Output is correct
31 Correct 435 ms 20024 KB Output is correct
32 Correct 442 ms 20128 KB Output is correct
33 Correct 437 ms 20032 KB Output is correct
34 Correct 297 ms 23408 KB Output is correct
35 Correct 433 ms 20016 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 543 ms 69064 KB Output is correct
40 Correct 513 ms 69112 KB Output is correct
41 Correct 527 ms 69272 KB Output is correct
42 Correct 395 ms 70960 KB Output is correct
43 Correct 399 ms 71128 KB Output is correct
44 Correct 379 ms 71152 KB Output is correct
45 Correct 501 ms 69212 KB Output is correct
46 Correct 338 ms 71156 KB Output is correct
47 Correct 2 ms 2688 KB Output is correct
48 Correct 308 ms 56220 KB Output is correct
49 Correct 311 ms 56292 KB Output is correct
50 Correct 310 ms 56196 KB Output is correct
51 Correct 312 ms 56188 KB Output is correct
52 Correct 332 ms 56192 KB Output is correct
53 Correct 335 ms 56136 KB Output is correct
54 Correct 312 ms 56172 KB Output is correct
55 Correct 292 ms 56248 KB Output is correct
56 Correct 314 ms 56164 KB Output is correct
57 Correct 313 ms 56152 KB Output is correct
58 Correct 308 ms 56452 KB Output is correct
59 Correct 298 ms 56056 KB Output is correct
60 Correct 297 ms 56876 KB Output is correct
61 Correct 303 ms 56144 KB Output is correct
62 Correct 427 ms 20240 KB Output is correct
63 Correct 246 ms 20188 KB Output is correct
64 Correct 381 ms 20216 KB Output is correct
65 Correct 378 ms 20224 KB Output is correct
66 Correct 360 ms 20308 KB Output is correct
67 Correct 462 ms 20212 KB Output is correct
68 Correct 429 ms 20232 KB Output is correct
69 Correct 432 ms 20232 KB Output is correct
70 Correct 419 ms 20232 KB Output is correct
71 Correct 279 ms 20652 KB Output is correct
72 Correct 412 ms 20256 KB Output is correct
73 Correct 452 ms 20372 KB Output is correct
74 Correct 409 ms 20196 KB Output is correct
75 Correct 411 ms 20296 KB Output is correct
76 Correct 286 ms 23612 KB Output is correct
77 Correct 430 ms 20416 KB Output is correct
78 Correct 724 ms 68132 KB Output is correct
79 Correct 517 ms 70144 KB Output is correct
80 Correct 653 ms 69128 KB Output is correct
81 Correct 638 ms 69172 KB Output is correct
82 Correct 622 ms 68268 KB Output is correct
83 Correct 695 ms 68412 KB Output is correct
84 Correct 710 ms 68148 KB Output is correct
85 Correct 685 ms 68124 KB Output is correct
86 Correct 668 ms 68296 KB Output is correct
87 Correct 526 ms 70224 KB Output is correct
88 Correct 708 ms 68264 KB Output is correct
89 Correct 713 ms 68172 KB Output is correct
90 Correct 723 ms 68200 KB Output is correct
91 Correct 670 ms 68112 KB Output is correct
92 Correct 530 ms 74456 KB Output is correct
93 Correct 682 ms 69424 KB Output is correct