답안 #676934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676934 2023-01-01T16:27:55 Z penguin133 꿈 (IOI13_dreaming) C++17
47 / 100
367 ms 65536 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

//#define int long long
typedef long long ll;
#define pi pair<int, ll>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

int vis[100005];
vector<pi>v[100005], adj[100005];
ll maxi = -1e9, pos;
vector<int> trav;
void dfs(int x, ll cur){
	if(vis[x])return;
	vis[x] = 1;
	trav.push_back(x);
	if(cur > maxi)maxi = cur, pos = x;
	for(auto [i, j] : v[x])dfs(i, cur + j);
}

void diam(int x, int p, ll cur){
	if(cur > maxi)maxi = cur, pos = x;
	for(auto [i, j] : v[x])if(i != p)diam(i, x, cur + j);
}

vector<int> mids, path;

void find(int cur, int tgt, int p){
	trav.push_back(cur);
	if(cur == tgt){
		path = trav;
		return;
	}
	for(auto [i, j] : v[cur])if(i != p)find(i, tgt, cur);
	trav.pop_back();
}

ll mx;

void recur(int x, int p, ll cur){
	mx = max(mx, cur);
	for(auto [i, j] : v[x])if(i != p)recur(i, x, cur + j);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	
	for(int i=0;i<M;i++)v[A[i]].push_back({B[i], T[i]}), v[B[i]].push_back({A[i], T[i]});
	for(int i=0;i<N;i++){
		if(!vis[i]){
			maxi = -1e9;
			dfs(i, 0);
			for(auto j : trav)vis[j] = 0;
			trav.clear();
			int pos2 = pos;
			maxi = -1e9;
			dfs(pos, 0);
			trav.clear();
			//cerr << pos << " " << pos2 << '\n';
			ll cur = 0;
			ll mn = 1e18; 
			find(pos2, pos, -1);
			int cent = path[0];
			trav.clear();
			for(int j=0;j<(int)path.size();j++){
				mx = max(cur, maxi - cur);
				for(auto [a, b] : v[path[j]]){
					if((!j || path[j-1] != a) && (j == (int)path.size() - 1 || path[j+1] != a))recur(a, path[j], b);
					if(j < (int)path.size() - 1 && a == path[j+1])cur += b;
				}
				if(mn > mx)mn = mx, cent = path[j];
			}
			//cerr << cent << '\n';
			mids.push_back(cent);
		}
	}
	//for(auto i : mids)cerr << i << " ";
	//cerr << '\n';
	ll mini = 1e18;
	for(int i=0;i<(int)mids.size();i++){
		for(int j=0;j<(int)mids.size();j++){
			if(j == i)continue;
			v[mids[i]].push_back({mids[j], L});
			v[mids[j]].push_back({mids[i], L});		
		}
		maxi = -1e9;
		diam(0, -1, 0);
		maxi = -1e9;
		diam(pos, -1, 0);
		//cerr << maxi << '\n';
		mini = min(mini, maxi);
		for(int j=0;j<(int)mids.size();j++){
			if(j == i)continue;
			v[mids[j]].pop_back();
		}
		for(int j=0;j<(int)mids.size()-1;j++)v[mids[i]].pop_back();
	}
	return mini;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 18720 KB Output is correct
2 Correct 66 ms 18732 KB Output is correct
3 Correct 40 ms 14076 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 13 ms 6228 KB Output is correct
6 Correct 17 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 30 ms 10036 KB Output is correct
9 Correct 72 ms 12092 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 69 ms 14052 KB Output is correct
12 Correct 90 ms 16540 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5012 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4960 KB Output is correct
6 Correct 3 ms 5012 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5012 KB Output is correct
9 Correct 4 ms 5008 KB Output is correct
10 Correct 3 ms 5008 KB Output is correct
11 Correct 4 ms 4984 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 5012 KB Output is correct
14 Correct 4 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5008 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5008 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 18720 KB Output is correct
2 Correct 66 ms 18732 KB Output is correct
3 Correct 40 ms 14076 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 13 ms 6228 KB Output is correct
6 Correct 17 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 30 ms 10036 KB Output is correct
9 Correct 72 ms 12092 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 69 ms 14052 KB Output is correct
12 Correct 90 ms 16540 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4960 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5012 KB Output is correct
22 Correct 4 ms 5008 KB Output is correct
23 Correct 3 ms 5008 KB Output is correct
24 Correct 4 ms 4984 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 5012 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 4 ms 5008 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 5008 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4956 KB Output is correct
38 Correct 3 ms 5012 KB Output is correct
39 Correct 66 ms 18816 KB Output is correct
40 Correct 61 ms 18760 KB Output is correct
41 Correct 41 ms 14136 KB Output is correct
42 Correct 10 ms 7080 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4964 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 4 ms 5012 KB Output is correct
47 Correct 3 ms 5008 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 5012 KB Output is correct
51 Correct 3 ms 4992 KB Output is correct
52 Correct 3 ms 5020 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 5008 KB Output is correct
55 Correct 3 ms 5008 KB Output is correct
56 Correct 3 ms 4960 KB Output is correct
57 Correct 145 ms 13192 KB Output is correct
58 Correct 111 ms 12840 KB Output is correct
59 Correct 111 ms 12824 KB Output is correct
60 Correct 124 ms 12680 KB Output is correct
61 Correct 106 ms 12740 KB Output is correct
62 Correct 107 ms 12444 KB Output is correct
63 Correct 104 ms 12480 KB Output is correct
64 Correct 84 ms 12372 KB Output is correct
65 Correct 88 ms 12400 KB Output is correct
66 Correct 112 ms 12384 KB Output is correct
67 Correct 106 ms 12852 KB Output is correct
68 Correct 108 ms 12924 KB Output is correct
69 Correct 172 ms 12716 KB Output is correct
70 Correct 138 ms 12628 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 6 ms 5192 KB Output is correct
73 Correct 4 ms 5292 KB Output is correct
74 Correct 6 ms 5280 KB Output is correct
75 Correct 5 ms 5204 KB Output is correct
76 Correct 4 ms 5204 KB Output is correct
77 Correct 5 ms 5316 KB Output is correct
78 Correct 6 ms 5264 KB Output is correct
79 Correct 4 ms 5272 KB Output is correct
80 Correct 113 ms 12824 KB Output is correct
81 Correct 101 ms 12924 KB Output is correct
82 Correct 167 ms 12752 KB Output is correct
83 Correct 112 ms 12748 KB Output is correct
84 Correct 4 ms 5212 KB Output is correct
85 Correct 4 ms 5216 KB Output is correct
86 Correct 5 ms 5164 KB Output is correct
87 Correct 7 ms 5216 KB Output is correct
88 Correct 5 ms 5176 KB Output is correct
89 Correct 5 ms 5152 KB Output is correct
90 Correct 5 ms 5204 KB Output is correct
91 Correct 4 ms 5204 KB Output is correct
92 Correct 4 ms 5192 KB Output is correct
93 Correct 5 ms 5148 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5016 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 3 ms 4948 KB Output is correct
99 Correct 3 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 4948 KB Output is correct
102 Correct 3 ms 4948 KB Output is correct
103 Correct 3 ms 4948 KB Output is correct
104 Correct 10 ms 6228 KB Output is correct
105 Correct 25 ms 8196 KB Output is correct
106 Correct 5 ms 4972 KB Output is correct
107 Correct 55 ms 10084 KB Output is correct
108 Correct 58 ms 12088 KB Output is correct
109 Correct 4 ms 5076 KB Output is correct
110 Correct 74 ms 13964 KB Output is correct
111 Correct 92 ms 16576 KB Output is correct
112 Correct 3 ms 5148 KB Output is correct
113 Correct 202 ms 20620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 367 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5012 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4960 KB Output is correct
6 Correct 3 ms 5012 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5012 KB Output is correct
9 Correct 4 ms 5008 KB Output is correct
10 Correct 3 ms 5008 KB Output is correct
11 Correct 4 ms 4984 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 5012 KB Output is correct
14 Correct 4 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5008 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5008 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 7 ms 5728 KB Output is correct
27 Correct 32 ms 7732 KB Output is correct
28 Correct 47 ms 9116 KB Output is correct
29 Correct 6 ms 5716 KB Output is correct
30 Correct 17 ms 7500 KB Output is correct
31 Correct 37 ms 8644 KB Output is correct
32 Correct 6 ms 5332 KB Output is correct
33 Correct 17 ms 7228 KB Output is correct
34 Correct 29 ms 8252 KB Output is correct
35 Correct 3 ms 5012 KB Output is correct
36 Correct 3 ms 5016 KB Output is correct
37 Correct 4 ms 5024 KB Output is correct
38 Correct 3 ms 5024 KB Output is correct
39 Correct 3 ms 4960 KB Output is correct
40 Correct 3 ms 5216 KB Output is correct
41 Correct 3 ms 5136 KB Output is correct
42 Correct 3 ms 5008 KB Output is correct
43 Correct 3 ms 5012 KB Output is correct
44 Correct 5 ms 4948 KB Output is correct
45 Correct 4 ms 5008 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 4960 KB Output is correct
49 Correct 3 ms 5012 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4920 KB Output is correct
54 Correct 6 ms 5460 KB Output is correct
55 Correct 5 ms 5460 KB Output is correct
56 Correct 155 ms 37852 KB Output is correct
57 Runtime error 188 ms 65536 KB Execution killed with signal 9
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 18720 KB Output is correct
2 Correct 66 ms 18732 KB Output is correct
3 Correct 40 ms 14076 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 13 ms 6228 KB Output is correct
6 Correct 17 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 30 ms 10036 KB Output is correct
9 Correct 72 ms 12092 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 69 ms 14052 KB Output is correct
12 Correct 90 ms 16540 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4960 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5012 KB Output is correct
22 Correct 4 ms 5008 KB Output is correct
23 Correct 3 ms 5008 KB Output is correct
24 Correct 4 ms 4984 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 5012 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 4 ms 5008 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 5008 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4956 KB Output is correct
38 Correct 3 ms 5012 KB Output is correct
39 Correct 66 ms 18816 KB Output is correct
40 Correct 61 ms 18760 KB Output is correct
41 Correct 41 ms 14136 KB Output is correct
42 Correct 10 ms 7080 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4964 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 4 ms 5012 KB Output is correct
47 Correct 3 ms 5008 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 5012 KB Output is correct
51 Correct 3 ms 4992 KB Output is correct
52 Correct 3 ms 5020 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 5008 KB Output is correct
55 Correct 3 ms 5008 KB Output is correct
56 Correct 3 ms 4960 KB Output is correct
57 Correct 145 ms 13192 KB Output is correct
58 Correct 111 ms 12840 KB Output is correct
59 Correct 111 ms 12824 KB Output is correct
60 Correct 124 ms 12680 KB Output is correct
61 Correct 106 ms 12740 KB Output is correct
62 Correct 107 ms 12444 KB Output is correct
63 Correct 104 ms 12480 KB Output is correct
64 Correct 84 ms 12372 KB Output is correct
65 Correct 88 ms 12400 KB Output is correct
66 Correct 112 ms 12384 KB Output is correct
67 Correct 106 ms 12852 KB Output is correct
68 Correct 108 ms 12924 KB Output is correct
69 Correct 172 ms 12716 KB Output is correct
70 Correct 138 ms 12628 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 6 ms 5192 KB Output is correct
73 Correct 4 ms 5292 KB Output is correct
74 Correct 6 ms 5280 KB Output is correct
75 Correct 5 ms 5204 KB Output is correct
76 Correct 4 ms 5204 KB Output is correct
77 Correct 5 ms 5316 KB Output is correct
78 Correct 6 ms 5264 KB Output is correct
79 Correct 4 ms 5272 KB Output is correct
80 Correct 113 ms 12824 KB Output is correct
81 Correct 101 ms 12924 KB Output is correct
82 Correct 167 ms 12752 KB Output is correct
83 Correct 112 ms 12748 KB Output is correct
84 Correct 4 ms 5212 KB Output is correct
85 Correct 4 ms 5216 KB Output is correct
86 Correct 5 ms 5164 KB Output is correct
87 Correct 7 ms 5216 KB Output is correct
88 Correct 5 ms 5176 KB Output is correct
89 Correct 5 ms 5152 KB Output is correct
90 Correct 5 ms 5204 KB Output is correct
91 Correct 4 ms 5204 KB Output is correct
92 Correct 4 ms 5192 KB Output is correct
93 Correct 5 ms 5148 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5016 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 3 ms 4948 KB Output is correct
99 Correct 3 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 3 ms 4948 KB Output is correct
102 Correct 3 ms 4948 KB Output is correct
103 Correct 3 ms 4948 KB Output is correct
104 Correct 10 ms 6228 KB Output is correct
105 Correct 25 ms 8196 KB Output is correct
106 Correct 5 ms 4972 KB Output is correct
107 Correct 55 ms 10084 KB Output is correct
108 Correct 58 ms 12088 KB Output is correct
109 Correct 4 ms 5076 KB Output is correct
110 Correct 74 ms 13964 KB Output is correct
111 Correct 92 ms 16576 KB Output is correct
112 Correct 3 ms 5148 KB Output is correct
113 Correct 202 ms 20620 KB Output is correct
114 Runtime error 367 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -