답안 #676931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676931 2023-01-01T16:24:56 Z penguin133 꿈 (IOI13_dreaming) C++17
47 / 100
344 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 = INT_MAX; 
			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 = INT_MAX;
	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 90 ms 22848 KB Output is correct
2 Correct 85 ms 22800 KB Output is correct
3 Correct 52 ms 16584 KB Output is correct
4 Correct 10 ms 7508 KB Output is correct
5 Correct 9 ms 6460 KB Output is correct
6 Correct 17 ms 8904 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 35 ms 11604 KB Output is correct
9 Correct 45 ms 14184 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 73 ms 17112 KB Output is correct
12 Correct 92 ms 20064 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 4924 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 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 5000 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 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 2 ms 4960 KB Output is correct
19 Correct 2 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 2 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 22848 KB Output is correct
2 Correct 85 ms 22800 KB Output is correct
3 Correct 52 ms 16584 KB Output is correct
4 Correct 10 ms 7508 KB Output is correct
5 Correct 9 ms 6460 KB Output is correct
6 Correct 17 ms 8904 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 35 ms 11604 KB Output is correct
9 Correct 45 ms 14184 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 73 ms 17112 KB Output is correct
12 Correct 92 ms 20064 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 4924 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 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 5000 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 2 ms 4960 KB Output is correct
32 Correct 2 ms 4948 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 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 93 ms 22848 KB Output is correct
40 Correct 86 ms 22720 KB Output is correct
41 Correct 51 ms 16584 KB Output is correct
42 Correct 10 ms 7508 KB Output is correct
43 Correct 3 ms 5000 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 2 ms 4948 KB Output is correct
46 Correct 2 ms 4924 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 3 ms 4948 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 4948 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 110 ms 16788 KB Output is correct
58 Correct 116 ms 16632 KB Output is correct
59 Correct 114 ms 16828 KB Output is correct
60 Correct 105 ms 16624 KB Output is correct
61 Correct 108 ms 16676 KB Output is correct
62 Correct 106 ms 16588 KB Output is correct
63 Correct 109 ms 16732 KB Output is correct
64 Correct 87 ms 16712 KB Output is correct
65 Correct 91 ms 16664 KB Output is correct
66 Correct 106 ms 16704 KB Output is correct
67 Correct 109 ms 16716 KB Output is correct
68 Correct 130 ms 16748 KB Output is correct
69 Correct 129 ms 16748 KB Output is correct
70 Correct 132 ms 16708 KB Output is correct
71 Correct 3 ms 4988 KB Output is correct
72 Correct 4 ms 5332 KB Output is correct
73 Correct 5 ms 5332 KB Output is correct
74 Correct 5 ms 5360 KB Output is correct
75 Correct 4 ms 5372 KB Output is correct
76 Correct 4 ms 5332 KB Output is correct
77 Correct 4 ms 5332 KB Output is correct
78 Correct 4 ms 5332 KB Output is correct
79 Correct 5 ms 5332 KB Output is correct
80 Correct 116 ms 16704 KB Output is correct
81 Correct 109 ms 16716 KB Output is correct
82 Correct 113 ms 16632 KB Output is correct
83 Correct 101 ms 16856 KB Output is correct
84 Correct 3 ms 5204 KB Output is correct
85 Correct 4 ms 5204 KB Output is correct
86 Correct 4 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5332 KB Output is correct
89 Correct 4 ms 5316 KB Output is correct
90 Correct 4 ms 5204 KB Output is correct
91 Correct 4 ms 5332 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 4 ms 5332 KB Output is correct
94 Correct 2 ms 4948 KB Output is correct
95 Correct 3 ms 4948 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 9 ms 6484 KB Output is correct
105 Correct 18 ms 8916 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 35 ms 11604 KB Output is correct
108 Correct 47 ms 14180 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 77 ms 17000 KB Output is correct
111 Correct 94 ms 20036 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 143 ms 25112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 344 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 4924 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 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 5000 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 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 2 ms 4960 KB Output is correct
19 Correct 2 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 2 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 8 ms 5796 KB Output is correct
27 Correct 22 ms 7764 KB Output is correct
28 Correct 50 ms 9676 KB Output is correct
29 Correct 7 ms 5716 KB Output is correct
30 Correct 21 ms 7424 KB Output is correct
31 Correct 43 ms 9036 KB Output is correct
32 Correct 6 ms 5332 KB Output is correct
33 Correct 18 ms 7124 KB Output is correct
34 Correct 35 ms 8660 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 2 ms 4948 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 2 ms 4948 KB Output is correct
45 Correct 3 ms 4960 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 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 4 ms 5588 KB Output is correct
55 Correct 4 ms 5588 KB Output is correct
56 Correct 156 ms 37836 KB Output is correct
57 Runtime error 177 ms 65536 KB Execution killed with signal 9
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 22848 KB Output is correct
2 Correct 85 ms 22800 KB Output is correct
3 Correct 52 ms 16584 KB Output is correct
4 Correct 10 ms 7508 KB Output is correct
5 Correct 9 ms 6460 KB Output is correct
6 Correct 17 ms 8904 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 35 ms 11604 KB Output is correct
9 Correct 45 ms 14184 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 73 ms 17112 KB Output is correct
12 Correct 92 ms 20064 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 4924 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 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 5000 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 2 ms 4960 KB Output is correct
32 Correct 2 ms 4948 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 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 93 ms 22848 KB Output is correct
40 Correct 86 ms 22720 KB Output is correct
41 Correct 51 ms 16584 KB Output is correct
42 Correct 10 ms 7508 KB Output is correct
43 Correct 3 ms 5000 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 2 ms 4948 KB Output is correct
46 Correct 2 ms 4924 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 3 ms 4948 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 4948 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 110 ms 16788 KB Output is correct
58 Correct 116 ms 16632 KB Output is correct
59 Correct 114 ms 16828 KB Output is correct
60 Correct 105 ms 16624 KB Output is correct
61 Correct 108 ms 16676 KB Output is correct
62 Correct 106 ms 16588 KB Output is correct
63 Correct 109 ms 16732 KB Output is correct
64 Correct 87 ms 16712 KB Output is correct
65 Correct 91 ms 16664 KB Output is correct
66 Correct 106 ms 16704 KB Output is correct
67 Correct 109 ms 16716 KB Output is correct
68 Correct 130 ms 16748 KB Output is correct
69 Correct 129 ms 16748 KB Output is correct
70 Correct 132 ms 16708 KB Output is correct
71 Correct 3 ms 4988 KB Output is correct
72 Correct 4 ms 5332 KB Output is correct
73 Correct 5 ms 5332 KB Output is correct
74 Correct 5 ms 5360 KB Output is correct
75 Correct 4 ms 5372 KB Output is correct
76 Correct 4 ms 5332 KB Output is correct
77 Correct 4 ms 5332 KB Output is correct
78 Correct 4 ms 5332 KB Output is correct
79 Correct 5 ms 5332 KB Output is correct
80 Correct 116 ms 16704 KB Output is correct
81 Correct 109 ms 16716 KB Output is correct
82 Correct 113 ms 16632 KB Output is correct
83 Correct 101 ms 16856 KB Output is correct
84 Correct 3 ms 5204 KB Output is correct
85 Correct 4 ms 5204 KB Output is correct
86 Correct 4 ms 5204 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5332 KB Output is correct
89 Correct 4 ms 5316 KB Output is correct
90 Correct 4 ms 5204 KB Output is correct
91 Correct 4 ms 5332 KB Output is correct
92 Correct 4 ms 5332 KB Output is correct
93 Correct 4 ms 5332 KB Output is correct
94 Correct 2 ms 4948 KB Output is correct
95 Correct 3 ms 4948 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 9 ms 6484 KB Output is correct
105 Correct 18 ms 8916 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 35 ms 11604 KB Output is correct
108 Correct 47 ms 14180 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 77 ms 17000 KB Output is correct
111 Correct 94 ms 20036 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 143 ms 25112 KB Output is correct
114 Runtime error 344 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -