답안 #676928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676928 2023-01-01T16:17:57 Z penguin133 꿈 (IOI13_dreaming) C++17
47 / 100
409 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] : adj[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<N;j++)adj[j] = v[j];
		for(int j=0;j<(int)mids.size();j++){
			if(j == i)continue;
			adj[mids[i]].push_back({mids[j], L});
			adj[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);
	}
	return mini;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 24136 KB Output is correct
2 Correct 117 ms 24008 KB Output is correct
3 Correct 73 ms 17564 KB Output is correct
4 Correct 14 ms 7764 KB Output is correct
5 Correct 10 ms 6688 KB Output is correct
6 Correct 18 ms 9248 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 36 ms 12180 KB Output is correct
9 Correct 47 ms 14796 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 78 ms 18192 KB Output is correct
12 Correct 93 ms 21188 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5012 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 5012 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5012 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 24136 KB Output is correct
2 Correct 117 ms 24008 KB Output is correct
3 Correct 73 ms 17564 KB Output is correct
4 Correct 14 ms 7764 KB Output is correct
5 Correct 10 ms 6688 KB Output is correct
6 Correct 18 ms 9248 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 36 ms 12180 KB Output is correct
9 Correct 47 ms 14796 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 78 ms 18192 KB Output is correct
12 Correct 93 ms 21188 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5012 KB Output is correct
19 Correct 3 ms 4948 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 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 5008 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 5016 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 4 ms 5012 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5016 KB Output is correct
34 Correct 3 ms 5012 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5012 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 94 ms 24100 KB Output is correct
40 Correct 88 ms 23952 KB Output is correct
41 Correct 53 ms 17552 KB Output is correct
42 Correct 10 ms 7764 KB Output is correct
43 Correct 3 ms 5008 KB Output is correct
44 Correct 3 ms 4956 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5012 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 5008 KB Output is correct
52 Correct 4 ms 4916 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 5008 KB Output is correct
56 Correct 3 ms 5012 KB Output is correct
57 Correct 115 ms 18056 KB Output is correct
58 Correct 119 ms 17976 KB Output is correct
59 Correct 144 ms 18144 KB Output is correct
60 Correct 115 ms 18052 KB Output is correct
61 Correct 109 ms 18164 KB Output is correct
62 Correct 131 ms 18200 KB Output is correct
63 Correct 103 ms 18164 KB Output is correct
64 Correct 97 ms 18096 KB Output is correct
65 Correct 98 ms 18368 KB Output is correct
66 Correct 115 ms 18344 KB Output is correct
67 Correct 129 ms 18208 KB Output is correct
68 Correct 109 ms 18112 KB Output is correct
69 Correct 107 ms 18384 KB Output is correct
70 Correct 152 ms 18252 KB Output is correct
71 Correct 3 ms 5012 KB Output is correct
72 Correct 6 ms 5420 KB Output is correct
73 Correct 4 ms 5332 KB Output is correct
74 Correct 5 ms 5316 KB Output is correct
75 Correct 5 ms 5320 KB Output is correct
76 Correct 5 ms 5332 KB Output is correct
77 Correct 4 ms 5408 KB Output is correct
78 Correct 5 ms 5408 KB Output is correct
79 Correct 5 ms 5404 KB Output is correct
80 Correct 145 ms 18108 KB Output is correct
81 Correct 133 ms 17980 KB Output is correct
82 Correct 104 ms 18232 KB Output is correct
83 Correct 118 ms 18320 KB Output is correct
84 Correct 5 ms 5332 KB Output is correct
85 Correct 5 ms 5280 KB Output is correct
86 Correct 5 ms 5332 KB Output is correct
87 Correct 6 ms 5332 KB Output is correct
88 Correct 4 ms 5332 KB Output is correct
89 Correct 6 ms 5332 KB Output is correct
90 Correct 4 ms 5332 KB Output is correct
91 Correct 4 ms 5320 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 5 ms 5332 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 4 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 5004 KB Output is correct
103 Correct 3 ms 5012 KB Output is correct
104 Correct 9 ms 6612 KB Output is correct
105 Correct 18 ms 9292 KB Output is correct
106 Correct 3 ms 5008 KB Output is correct
107 Correct 35 ms 12108 KB Output is correct
108 Correct 48 ms 14872 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 99 ms 18248 KB Output is correct
111 Correct 100 ms 21144 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 179 ms 26684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 409 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5012 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 5012 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5012 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 8 ms 5716 KB Output is correct
27 Correct 24 ms 7800 KB Output is correct
28 Correct 50 ms 9796 KB Output is correct
29 Correct 7 ms 5716 KB Output is correct
30 Correct 20 ms 7508 KB Output is correct
31 Correct 45 ms 9132 KB Output is correct
32 Correct 6 ms 5404 KB Output is correct
33 Correct 17 ms 7076 KB Output is correct
34 Correct 44 ms 8664 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5040 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 5008 KB Output is correct
39 Correct 3 ms 5008 KB Output is correct
40 Correct 3 ms 5204 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 5008 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4984 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 5012 KB Output is correct
54 Correct 4 ms 5588 KB Output is correct
55 Correct 4 ms 5588 KB Output is correct
56 Correct 166 ms 37928 KB Output is correct
57 Runtime error 178 ms 65536 KB Execution killed with signal 9
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 24136 KB Output is correct
2 Correct 117 ms 24008 KB Output is correct
3 Correct 73 ms 17564 KB Output is correct
4 Correct 14 ms 7764 KB Output is correct
5 Correct 10 ms 6688 KB Output is correct
6 Correct 18 ms 9248 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 36 ms 12180 KB Output is correct
9 Correct 47 ms 14796 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 78 ms 18192 KB Output is correct
12 Correct 93 ms 21188 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5012 KB Output is correct
19 Correct 3 ms 4948 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 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 5008 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 5016 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 4 ms 5012 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5016 KB Output is correct
34 Correct 3 ms 5012 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5012 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 94 ms 24100 KB Output is correct
40 Correct 88 ms 23952 KB Output is correct
41 Correct 53 ms 17552 KB Output is correct
42 Correct 10 ms 7764 KB Output is correct
43 Correct 3 ms 5008 KB Output is correct
44 Correct 3 ms 4956 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5012 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 5008 KB Output is correct
52 Correct 4 ms 4916 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 5008 KB Output is correct
56 Correct 3 ms 5012 KB Output is correct
57 Correct 115 ms 18056 KB Output is correct
58 Correct 119 ms 17976 KB Output is correct
59 Correct 144 ms 18144 KB Output is correct
60 Correct 115 ms 18052 KB Output is correct
61 Correct 109 ms 18164 KB Output is correct
62 Correct 131 ms 18200 KB Output is correct
63 Correct 103 ms 18164 KB Output is correct
64 Correct 97 ms 18096 KB Output is correct
65 Correct 98 ms 18368 KB Output is correct
66 Correct 115 ms 18344 KB Output is correct
67 Correct 129 ms 18208 KB Output is correct
68 Correct 109 ms 18112 KB Output is correct
69 Correct 107 ms 18384 KB Output is correct
70 Correct 152 ms 18252 KB Output is correct
71 Correct 3 ms 5012 KB Output is correct
72 Correct 6 ms 5420 KB Output is correct
73 Correct 4 ms 5332 KB Output is correct
74 Correct 5 ms 5316 KB Output is correct
75 Correct 5 ms 5320 KB Output is correct
76 Correct 5 ms 5332 KB Output is correct
77 Correct 4 ms 5408 KB Output is correct
78 Correct 5 ms 5408 KB Output is correct
79 Correct 5 ms 5404 KB Output is correct
80 Correct 145 ms 18108 KB Output is correct
81 Correct 133 ms 17980 KB Output is correct
82 Correct 104 ms 18232 KB Output is correct
83 Correct 118 ms 18320 KB Output is correct
84 Correct 5 ms 5332 KB Output is correct
85 Correct 5 ms 5280 KB Output is correct
86 Correct 5 ms 5332 KB Output is correct
87 Correct 6 ms 5332 KB Output is correct
88 Correct 4 ms 5332 KB Output is correct
89 Correct 6 ms 5332 KB Output is correct
90 Correct 4 ms 5332 KB Output is correct
91 Correct 4 ms 5320 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 5 ms 5332 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 4 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 5004 KB Output is correct
103 Correct 3 ms 5012 KB Output is correct
104 Correct 9 ms 6612 KB Output is correct
105 Correct 18 ms 9292 KB Output is correct
106 Correct 3 ms 5008 KB Output is correct
107 Correct 35 ms 12108 KB Output is correct
108 Correct 48 ms 14872 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 99 ms 18248 KB Output is correct
111 Correct 100 ms 21144 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 179 ms 26684 KB Output is correct
114 Runtime error 409 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -