Submission #676936

# Submission time Handle Problem Language Result Execution time Memory
676936 2023-01-01T16:31:26 Z penguin133 Dreaming (IOI13_dreaming) C++17
47 / 100
613 ms 65536 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
 
//#define int long long
typedef int 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){
  vis[x] = 1;
	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;
			diam(i, -1, 0);
			int pos2 = pos;
			maxi = -1e9;
			diam(pos, -1, 0);
			//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<(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;
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 17228 KB Output is correct
2 Correct 56 ms 17240 KB Output is correct
3 Correct 34 ms 12984 KB Output is correct
4 Correct 9 ms 6740 KB Output is correct
5 Correct 9 ms 5844 KB Output is correct
6 Correct 16 ms 7712 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 30 ms 9068 KB Output is correct
9 Correct 38 ms 10936 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 59 ms 12452 KB Output is correct
12 Correct 66 ms 14744 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 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 4 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 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 17228 KB Output is correct
2 Correct 56 ms 17240 KB Output is correct
3 Correct 34 ms 12984 KB Output is correct
4 Correct 9 ms 6740 KB Output is correct
5 Correct 9 ms 5844 KB Output is correct
6 Correct 16 ms 7712 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 30 ms 9068 KB Output is correct
9 Correct 38 ms 10936 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 59 ms 12452 KB Output is correct
12 Correct 66 ms 14744 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 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 4 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 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 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 72 ms 17152 KB Output is correct
40 Correct 58 ms 17120 KB Output is correct
41 Correct 34 ms 13008 KB Output is correct
42 Correct 9 ms 6740 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 2 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 4948 KB Output is correct
49 Correct 3 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 3 ms 4948 KB Output is correct
54 Correct 2 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 2 ms 4948 KB Output is correct
57 Correct 87 ms 10540 KB Output is correct
58 Correct 79 ms 10536 KB Output is correct
59 Correct 101 ms 10572 KB Output is correct
60 Correct 116 ms 10428 KB Output is correct
61 Correct 73 ms 10316 KB Output is correct
62 Correct 74 ms 10324 KB Output is correct
63 Correct 69 ms 10220 KB Output is correct
64 Correct 72 ms 10316 KB Output is correct
65 Correct 70 ms 10188 KB Output is correct
66 Correct 70 ms 10216 KB Output is correct
67 Correct 78 ms 10484 KB Output is correct
68 Correct 81 ms 10436 KB Output is correct
69 Correct 122 ms 10428 KB Output is correct
70 Correct 81 ms 10444 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 4 ms 5076 KB Output is correct
73 Correct 4 ms 5204 KB Output is correct
74 Correct 4 ms 5076 KB Output is correct
75 Correct 4 ms 5076 KB Output is correct
76 Correct 4 ms 5076 KB Output is correct
77 Correct 4 ms 5076 KB Output is correct
78 Correct 4 ms 5076 KB Output is correct
79 Correct 4 ms 5076 KB Output is correct
80 Correct 117 ms 10460 KB Output is correct
81 Correct 104 ms 10416 KB Output is correct
82 Correct 85 ms 10440 KB Output is correct
83 Correct 75 ms 10328 KB Output is correct
84 Correct 3 ms 5076 KB Output is correct
85 Correct 3 ms 5076 KB Output is correct
86 Correct 4 ms 5076 KB Output is correct
87 Correct 4 ms 5076 KB Output is correct
88 Correct 4 ms 5076 KB Output is correct
89 Correct 4 ms 5076 KB Output is correct
90 Correct 4 ms 5076 KB Output is correct
91 Correct 4 ms 5076 KB Output is correct
92 Correct 4 ms 5076 KB Output is correct
93 Correct 5 ms 5076 KB Output is correct
94 Correct 3 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 2 ms 4992 KB Output is correct
99 Correct 2 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 2 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 8 ms 5844 KB Output is correct
105 Correct 18 ms 7600 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 36 ms 9036 KB Output is correct
108 Correct 41 ms 10944 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 56 ms 12400 KB Output is correct
111 Correct 87 ms 14800 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 107 ms 18428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 613 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 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 4 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 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 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 7 ms 5332 KB Output is correct
27 Correct 24 ms 6352 KB Output is correct
28 Correct 46 ms 7164 KB Output is correct
29 Correct 7 ms 5332 KB Output is correct
30 Correct 17 ms 6228 KB Output is correct
31 Correct 36 ms 6868 KB Output is correct
32 Correct 5 ms 5224 KB Output is correct
33 Correct 14 ms 6100 KB Output is correct
34 Correct 32 ms 6636 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 3 ms 4948 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 2 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 4948 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 2 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 4948 KB Output is correct
54 Correct 4 ms 5332 KB Output is correct
55 Correct 4 ms 5332 KB Output is correct
56 Correct 144 ms 24088 KB Output is correct
57 Correct 308 ms 59724 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 5 ms 5148 KB Output is correct
60 Correct 209 ms 32832 KB Output is correct
61 Correct 285 ms 50788 KB Output is correct
62 Correct 4 ms 5152 KB Output is correct
63 Correct 5 ms 5204 KB Output is correct
64 Runtime error 333 ms 65536 KB Execution killed with signal 9
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 17228 KB Output is correct
2 Correct 56 ms 17240 KB Output is correct
3 Correct 34 ms 12984 KB Output is correct
4 Correct 9 ms 6740 KB Output is correct
5 Correct 9 ms 5844 KB Output is correct
6 Correct 16 ms 7712 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 30 ms 9068 KB Output is correct
9 Correct 38 ms 10936 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 59 ms 12452 KB Output is correct
12 Correct 66 ms 14744 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 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 4 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 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 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 72 ms 17152 KB Output is correct
40 Correct 58 ms 17120 KB Output is correct
41 Correct 34 ms 13008 KB Output is correct
42 Correct 9 ms 6740 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 2 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 4948 KB Output is correct
49 Correct 3 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 3 ms 4948 KB Output is correct
54 Correct 2 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 2 ms 4948 KB Output is correct
57 Correct 87 ms 10540 KB Output is correct
58 Correct 79 ms 10536 KB Output is correct
59 Correct 101 ms 10572 KB Output is correct
60 Correct 116 ms 10428 KB Output is correct
61 Correct 73 ms 10316 KB Output is correct
62 Correct 74 ms 10324 KB Output is correct
63 Correct 69 ms 10220 KB Output is correct
64 Correct 72 ms 10316 KB Output is correct
65 Correct 70 ms 10188 KB Output is correct
66 Correct 70 ms 10216 KB Output is correct
67 Correct 78 ms 10484 KB Output is correct
68 Correct 81 ms 10436 KB Output is correct
69 Correct 122 ms 10428 KB Output is correct
70 Correct 81 ms 10444 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 4 ms 5076 KB Output is correct
73 Correct 4 ms 5204 KB Output is correct
74 Correct 4 ms 5076 KB Output is correct
75 Correct 4 ms 5076 KB Output is correct
76 Correct 4 ms 5076 KB Output is correct
77 Correct 4 ms 5076 KB Output is correct
78 Correct 4 ms 5076 KB Output is correct
79 Correct 4 ms 5076 KB Output is correct
80 Correct 117 ms 10460 KB Output is correct
81 Correct 104 ms 10416 KB Output is correct
82 Correct 85 ms 10440 KB Output is correct
83 Correct 75 ms 10328 KB Output is correct
84 Correct 3 ms 5076 KB Output is correct
85 Correct 3 ms 5076 KB Output is correct
86 Correct 4 ms 5076 KB Output is correct
87 Correct 4 ms 5076 KB Output is correct
88 Correct 4 ms 5076 KB Output is correct
89 Correct 4 ms 5076 KB Output is correct
90 Correct 4 ms 5076 KB Output is correct
91 Correct 4 ms 5076 KB Output is correct
92 Correct 4 ms 5076 KB Output is correct
93 Correct 5 ms 5076 KB Output is correct
94 Correct 3 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 2 ms 4992 KB Output is correct
99 Correct 2 ms 4948 KB Output is correct
100 Correct 3 ms 4948 KB Output is correct
101 Correct 2 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 8 ms 5844 KB Output is correct
105 Correct 18 ms 7600 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 36 ms 9036 KB Output is correct
108 Correct 41 ms 10944 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 56 ms 12400 KB Output is correct
111 Correct 87 ms 14800 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 107 ms 18428 KB Output is correct
114 Runtime error 613 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -