Submission #676930

# Submission time Handle Problem Language Result Execution time Memory
676930 2023-01-01T16:24:34 Z penguin133 Dreaming (IOI13_dreaming) C++17
47 / 100
679 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){
	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;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:66:12: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
   66 |    ll mn = 1e18;
      |            ^~~~
dreaming.cpp:84:12: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
   84 |  ll mini = 1e18;
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19952 KB Output is correct
2 Correct 81 ms 19960 KB Output is correct
3 Correct 44 ms 14748 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 16 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10236 KB Output is correct
9 Correct 41 ms 12276 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 61 ms 14560 KB Output is correct
12 Correct 71 ms 17216 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 3 ms 4948 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 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 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 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 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 2 ms 4948 KB Output is correct
20 Correct 3 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 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
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19952 KB Output is correct
2 Correct 81 ms 19960 KB Output is correct
3 Correct 44 ms 14748 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 16 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10236 KB Output is correct
9 Correct 41 ms 12276 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 61 ms 14560 KB Output is correct
12 Correct 71 ms 17216 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 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 2 ms 4948 KB Output is correct
20 Correct 3 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 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 2 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 2 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 3 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 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 76 ms 20004 KB Output is correct
40 Correct 80 ms 19920 KB Output is correct
41 Correct 45 ms 14804 KB Output is correct
42 Correct 10 ms 7184 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 2 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 4992 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 5028 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 2 ms 4948 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 90 ms 13636 KB Output is correct
58 Correct 88 ms 13504 KB Output is correct
59 Correct 98 ms 13844 KB Output is correct
60 Correct 90 ms 13704 KB Output is correct
61 Correct 81 ms 13960 KB Output is correct
62 Correct 84 ms 13864 KB Output is correct
63 Correct 80 ms 13968 KB Output is correct
64 Correct 76 ms 13840 KB Output is correct
65 Correct 91 ms 13964 KB Output is correct
66 Correct 79 ms 13960 KB Output is correct
67 Correct 90 ms 13828 KB Output is correct
68 Correct 103 ms 13792 KB Output is correct
69 Correct 92 ms 13640 KB Output is correct
70 Correct 96 ms 13640 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 4 ms 5204 KB Output is correct
73 Correct 6 ms 5204 KB Output is correct
74 Correct 4 ms 5204 KB Output is correct
75 Correct 4 ms 5204 KB Output is correct
76 Correct 5 ms 5276 KB Output is correct
77 Correct 4 ms 5204 KB Output is correct
78 Correct 4 ms 5204 KB Output is correct
79 Correct 4 ms 5204 KB Output is correct
80 Correct 98 ms 13624 KB Output is correct
81 Correct 92 ms 13672 KB Output is correct
82 Correct 96 ms 13940 KB Output is correct
83 Correct 86 ms 13900 KB Output is correct
84 Correct 4 ms 5204 KB Output is correct
85 Correct 3 ms 5204 KB Output is correct
86 Correct 4 ms 5152 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5276 KB Output is correct
89 Correct 4 ms 5204 KB Output is correct
90 Correct 4 ms 5248 KB Output is correct
91 Correct 4 ms 5204 KB Output is correct
92 Correct 4 ms 5204 KB Output is correct
93 Correct 4 ms 5204 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 2 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 2 ms 4948 KB Output is correct
100 Correct 2 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 6220 KB Output is correct
105 Correct 17 ms 8176 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 31 ms 10196 KB Output is correct
108 Correct 41 ms 12352 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 61 ms 14576 KB Output is correct
111 Correct 83 ms 17304 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 119 ms 21360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 679 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 3 ms 4948 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 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 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 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 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 2 ms 4948 KB Output is correct
20 Correct 3 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 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 7 ms 5332 KB Output is correct
27 Correct 22 ms 6432 KB Output is correct
28 Correct 48 ms 7504 KB Output is correct
29 Correct 8 ms 5332 KB Output is correct
30 Correct 19 ms 6228 KB Output is correct
31 Correct 42 ms 7208 KB Output is correct
32 Correct 6 ms 5204 KB Output is correct
33 Correct 16 ms 6100 KB Output is correct
34 Correct 34 ms 6908 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 3 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 3 ms 4948 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 3 ms 5008 KB Output is correct
46 Correct 2 ms 4948 KB Output is correct
47 Correct 3 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 3 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 4892 KB Output is correct
54 Correct 4 ms 5460 KB Output is correct
55 Correct 6 ms 5460 KB Output is correct
56 Correct 144 ms 24140 KB Output is correct
57 Correct 273 ms 59588 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 4 ms 5332 KB Output is correct
60 Correct 194 ms 32972 KB Output is correct
61 Correct 272 ms 51032 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 5 ms 5204 KB Output is correct
64 Runtime error 255 ms 65536 KB Execution killed with signal 9
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19952 KB Output is correct
2 Correct 81 ms 19960 KB Output is correct
3 Correct 44 ms 14748 KB Output is correct
4 Correct 10 ms 7124 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 16 ms 8276 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 31 ms 10236 KB Output is correct
9 Correct 41 ms 12276 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 61 ms 14560 KB Output is correct
12 Correct 71 ms 17216 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 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 2 ms 4948 KB Output is correct
20 Correct 3 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 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 2 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 2 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 3 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 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 76 ms 20004 KB Output is correct
40 Correct 80 ms 19920 KB Output is correct
41 Correct 45 ms 14804 KB Output is correct
42 Correct 10 ms 7184 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 2 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 4992 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 5028 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 2 ms 4948 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 90 ms 13636 KB Output is correct
58 Correct 88 ms 13504 KB Output is correct
59 Correct 98 ms 13844 KB Output is correct
60 Correct 90 ms 13704 KB Output is correct
61 Correct 81 ms 13960 KB Output is correct
62 Correct 84 ms 13864 KB Output is correct
63 Correct 80 ms 13968 KB Output is correct
64 Correct 76 ms 13840 KB Output is correct
65 Correct 91 ms 13964 KB Output is correct
66 Correct 79 ms 13960 KB Output is correct
67 Correct 90 ms 13828 KB Output is correct
68 Correct 103 ms 13792 KB Output is correct
69 Correct 92 ms 13640 KB Output is correct
70 Correct 96 ms 13640 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 4 ms 5204 KB Output is correct
73 Correct 6 ms 5204 KB Output is correct
74 Correct 4 ms 5204 KB Output is correct
75 Correct 4 ms 5204 KB Output is correct
76 Correct 5 ms 5276 KB Output is correct
77 Correct 4 ms 5204 KB Output is correct
78 Correct 4 ms 5204 KB Output is correct
79 Correct 4 ms 5204 KB Output is correct
80 Correct 98 ms 13624 KB Output is correct
81 Correct 92 ms 13672 KB Output is correct
82 Correct 96 ms 13940 KB Output is correct
83 Correct 86 ms 13900 KB Output is correct
84 Correct 4 ms 5204 KB Output is correct
85 Correct 3 ms 5204 KB Output is correct
86 Correct 4 ms 5152 KB Output is correct
87 Correct 4 ms 5204 KB Output is correct
88 Correct 4 ms 5276 KB Output is correct
89 Correct 4 ms 5204 KB Output is correct
90 Correct 4 ms 5248 KB Output is correct
91 Correct 4 ms 5204 KB Output is correct
92 Correct 4 ms 5204 KB Output is correct
93 Correct 4 ms 5204 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 2 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 2 ms 4948 KB Output is correct
100 Correct 2 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 6220 KB Output is correct
105 Correct 17 ms 8176 KB Output is correct
106 Correct 3 ms 4948 KB Output is correct
107 Correct 31 ms 10196 KB Output is correct
108 Correct 41 ms 12352 KB Output is correct
109 Correct 3 ms 5076 KB Output is correct
110 Correct 61 ms 14576 KB Output is correct
111 Correct 83 ms 17304 KB Output is correct
112 Correct 3 ms 5076 KB Output is correct
113 Correct 119 ms 21360 KB Output is correct
114 Runtime error 679 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -