Submission #546792

# Submission time Handle Problem Language Result Execution time Memory
546792 2022-04-08T13:39:04 Z lovrot Dreaming (IOI13_dreaming) C++11
47 / 100
308 ms 21484 KB
#include <bits/stdc++.h>
#include"dreaming.h"

#define X first
#define Y second
#define pii pair<int, int> 
#define pb push_back

using namespace std;
 
const int MN = 100010;
const int INF = 1e9 + 10;

int n, m, l;
int min_max[MN], c[MN];
int nxt[MN], maxp[MN], h[MN], nxte[MN];

bool mark[MN], bio[MN];

vector<pii> g[MN];
vector<int> used; 
set<int> s;
 
int Find(int x){ 
	//cout << x << " +\n";
	if(h[x] == x)
		return x;
	return h[x] = Find(h[x]);
}
 
void Union(int x, int y){ 
	h[x] = Find(y);
}
 
void use(int x){ 
	if(!mark[x]){ 
		used.pb(x);
		mark[x] = true;
	}
}

int maxPath(int x){
	use(x);
	bio[x] = true;
	maxp[x] = 0;
	int mi = x;
	for(pair<int, int> e : g[x]){
		int y = e.X;
		if(bio[y])
			continue;

		int val = e.Y; 
		int f = maxPath(y);
		if(maxp[y] + val > maxp[x]){ 
			maxp[x] = maxp[y] + val;
			mi = f;
			nxt[x] = y;
			nxte[x] = val;
		}
	}

	//cout << x << " " << maxp[x] << " " << mi << "\n";

	return mi;
}
 
void clearUsed(){ 
	for(int x : used){
		nxt[x] = 0;
		maxp[x] = 0;
		mark[x] = false;
		bio[x] = 0;
		nxte[x] = 0;
	}
	used.clear();
}
 
pii findCenter(int x, bool printp){ 
	clearUsed();
	x = maxPath(x);	
	clearUsed();
	int y = maxPath(x);

	int s = maxp[x]; 
 	int zb = 0;

 	if(printp){ 
 		return {s, 0};
 	}

	int mn = INF, mni = x; 
	while(x != y){ 
		if(mn > max(zb, s - zb)){ 
			mn = max(zb, s - zb);
			mni = x;
		}	
		//cout << x << " -> " << nxt[x] << " (" << nxte[x] << " " << zb << ")\n";
		zb += nxte[x]; 
		x = nxt[x];
	}

	if(mn == INF)
		mn = 0;

	return {mni, mn};
}
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	ios_base::sync_with_stdio(false);
	
	for(int i = 0; i < MN; i++){
		h[i] = i;
		c[i] = i;
	}
 
	//cin >> n >> m >> l;
 	n = N;
 	m = M;
 	l = L;

	for(int i = 0; i < n; i++)
		s.insert(i);
 
	for(int i = 0; i < m; i++){ 
		int a, b, t;
		//cin >> a >> b >> t;
 		a = A[i];
 		b = B[i]; 
 		t = T[i];

		g[a].push_back({b, t});
		g[b].push_back({a, t});
		a = Find(a);
		b = Find(b);
		
		s.erase(a);
		s.erase(b);
		Union(a, b);
		s.insert(Find(a));
	}
 	
	auto it = s.begin();
	while(it != s.end()){ 
		pii res = findCenter(*it, 0);
		
		c[*it] = res.X;
		min_max[*it] = res.Y;

		it++;
	}

	while(s.size() > 1){
		auto it = s.begin(); 
		int a = *it;
		it++; 
		int b = *it;

		int ca = c[a], av = min_max[a];
		int cb = c[b], bv = min_max[b]; 
		
		s.erase(a);
		s.erase(b);
		Union(a, b);
		g[ca].pb({cb, l});
		g[cb].pb({ca, l});

		int nh = Find(a);
		s.insert(nh);

		if(max(av, bv + l) > max(bv, av + l)){
			swap(ca, cb);
			swap(av, bv);
		}
		c[nh] = ca;
		min_max[nh] = max(av, bv + l);
	}
	pii ret = findCenter(*(s.begin()), 1);
	return ret.X;
}
/*
int main(){ 
	int n, m, l;
	int a[MN], b[MN], t[MN]; 
	cin >> n >> m >> l;
	for(int i = 0; i < m; i++)
		cin >> a[i] >> b[i] >> t[i];
	cout << travelTime(n, m, l, a, b, t) << "\n";
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 184 ms 17680 KB Output is correct
2 Correct 162 ms 18964 KB Output is correct
3 Correct 87 ms 13864 KB Output is correct
4 Correct 15 ms 5868 KB Output is correct
5 Correct 13 ms 4948 KB Output is correct
6 Correct 29 ms 7276 KB Output is correct
7 Correct 3 ms 3540 KB Output is correct
8 Correct 86 ms 9524 KB Output is correct
9 Correct 82 ms 11572 KB Output is correct
10 Correct 3 ms 3540 KB Output is correct
11 Correct 132 ms 14624 KB Output is correct
12 Correct 184 ms 16996 KB Output is correct
13 Correct 3 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3432 KB Output is correct
3 Correct 3 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 3 ms 3412 KB Output is correct
10 Correct 3 ms 3540 KB Output is correct
11 Correct 4 ms 3412 KB Output is correct
12 Correct 3 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3432 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 3 ms 3540 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3436 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3432 KB Output is correct
24 Correct 2 ms 3432 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 17680 KB Output is correct
2 Correct 162 ms 18964 KB Output is correct
3 Correct 87 ms 13864 KB Output is correct
4 Correct 15 ms 5868 KB Output is correct
5 Correct 13 ms 4948 KB Output is correct
6 Correct 29 ms 7276 KB Output is correct
7 Correct 3 ms 3540 KB Output is correct
8 Correct 86 ms 9524 KB Output is correct
9 Correct 82 ms 11572 KB Output is correct
10 Correct 3 ms 3540 KB Output is correct
11 Correct 132 ms 14624 KB Output is correct
12 Correct 184 ms 16996 KB Output is correct
13 Correct 3 ms 3540 KB Output is correct
14 Correct 3 ms 3412 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 3 ms 3412 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 4 ms 3412 KB Output is correct
25 Correct 3 ms 3412 KB Output is correct
26 Correct 2 ms 3412 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3432 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 3 ms 3540 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 2 ms 3436 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3432 KB Output is correct
37 Correct 2 ms 3432 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 170 ms 18992 KB Output is correct
40 Correct 196 ms 18932 KB Output is correct
41 Correct 89 ms 13868 KB Output is correct
42 Correct 16 ms 5876 KB Output is correct
43 Correct 2 ms 3412 KB Output is correct
44 Correct 2 ms 3412 KB Output is correct
45 Correct 3 ms 3432 KB Output is correct
46 Correct 3 ms 3432 KB Output is correct
47 Correct 2 ms 3424 KB Output is correct
48 Correct 3 ms 3412 KB Output is correct
49 Correct 3 ms 3412 KB Output is correct
50 Correct 3 ms 3432 KB Output is correct
51 Correct 3 ms 3432 KB Output is correct
52 Correct 3 ms 3412 KB Output is correct
53 Correct 3 ms 3432 KB Output is correct
54 Correct 2 ms 3412 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 2 ms 3412 KB Output is correct
57 Correct 208 ms 13400 KB Output is correct
58 Correct 261 ms 13408 KB Output is correct
59 Correct 220 ms 13512 KB Output is correct
60 Correct 253 ms 13592 KB Output is correct
61 Correct 209 ms 13700 KB Output is correct
62 Correct 203 ms 13668 KB Output is correct
63 Correct 245 ms 13132 KB Output is correct
64 Correct 198 ms 13128 KB Output is correct
65 Correct 194 ms 13432 KB Output is correct
66 Correct 246 ms 13500 KB Output is correct
67 Correct 216 ms 13620 KB Output is correct
68 Correct 199 ms 13656 KB Output is correct
69 Correct 308 ms 13824 KB Output is correct
70 Correct 199 ms 13816 KB Output is correct
71 Correct 2 ms 3412 KB Output is correct
72 Correct 5 ms 3756 KB Output is correct
73 Correct 5 ms 3828 KB Output is correct
74 Correct 6 ms 3860 KB Output is correct
75 Correct 5 ms 3796 KB Output is correct
76 Correct 6 ms 3796 KB Output is correct
77 Correct 5 ms 3828 KB Output is correct
78 Correct 7 ms 3824 KB Output is correct
79 Correct 6 ms 3796 KB Output is correct
80 Correct 216 ms 13624 KB Output is correct
81 Correct 197 ms 13592 KB Output is correct
82 Correct 203 ms 13572 KB Output is correct
83 Correct 247 ms 13700 KB Output is correct
84 Correct 4 ms 3668 KB Output is correct
85 Correct 4 ms 3668 KB Output is correct
86 Correct 4 ms 3668 KB Output is correct
87 Correct 4 ms 3696 KB Output is correct
88 Correct 5 ms 3796 KB Output is correct
89 Correct 4 ms 3700 KB Output is correct
90 Correct 5 ms 3796 KB Output is correct
91 Correct 6 ms 3796 KB Output is correct
92 Correct 5 ms 3796 KB Output is correct
93 Correct 5 ms 3700 KB Output is correct
94 Correct 3 ms 3412 KB Output is correct
95 Correct 2 ms 3412 KB Output is correct
96 Correct 3 ms 3428 KB Output is correct
97 Correct 3 ms 3412 KB Output is correct
98 Correct 2 ms 3420 KB Output is correct
99 Correct 2 ms 3412 KB Output is correct
100 Correct 2 ms 3412 KB Output is correct
101 Correct 2 ms 3412 KB Output is correct
102 Correct 2 ms 3408 KB Output is correct
103 Correct 2 ms 3412 KB Output is correct
104 Correct 14 ms 4940 KB Output is correct
105 Correct 27 ms 7144 KB Output is correct
106 Correct 3 ms 3484 KB Output is correct
107 Correct 66 ms 9452 KB Output is correct
108 Correct 101 ms 11576 KB Output is correct
109 Correct 4 ms 3540 KB Output is correct
110 Correct 133 ms 14640 KB Output is correct
111 Correct 160 ms 16860 KB Output is correct
112 Correct 3 ms 3540 KB Output is correct
113 Correct 238 ms 21484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 12136 KB Output is correct
2 Incorrect 112 ms 12204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3432 KB Output is correct
3 Correct 3 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 3 ms 3412 KB Output is correct
10 Correct 3 ms 3540 KB Output is correct
11 Correct 4 ms 3412 KB Output is correct
12 Correct 3 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3432 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 3 ms 3540 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3436 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3432 KB Output is correct
24 Correct 2 ms 3432 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
26 Correct 4 ms 3540 KB Output is correct
27 Correct 4 ms 3668 KB Output is correct
28 Correct 5 ms 3828 KB Output is correct
29 Correct 3 ms 3568 KB Output is correct
30 Correct 5 ms 3588 KB Output is correct
31 Correct 6 ms 3796 KB Output is correct
32 Correct 4 ms 3540 KB Output is correct
33 Correct 4 ms 3668 KB Output is correct
34 Correct 5 ms 3828 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3428 KB Output is correct
37 Correct 2 ms 3412 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 2 ms 3412 KB Output is correct
40 Incorrect 2 ms 3412 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 184 ms 17680 KB Output is correct
2 Correct 162 ms 18964 KB Output is correct
3 Correct 87 ms 13864 KB Output is correct
4 Correct 15 ms 5868 KB Output is correct
5 Correct 13 ms 4948 KB Output is correct
6 Correct 29 ms 7276 KB Output is correct
7 Correct 3 ms 3540 KB Output is correct
8 Correct 86 ms 9524 KB Output is correct
9 Correct 82 ms 11572 KB Output is correct
10 Correct 3 ms 3540 KB Output is correct
11 Correct 132 ms 14624 KB Output is correct
12 Correct 184 ms 16996 KB Output is correct
13 Correct 3 ms 3540 KB Output is correct
14 Correct 3 ms 3412 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 3 ms 3412 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 4 ms 3412 KB Output is correct
25 Correct 3 ms 3412 KB Output is correct
26 Correct 2 ms 3412 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3432 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 3 ms 3540 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 2 ms 3436 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3432 KB Output is correct
37 Correct 2 ms 3432 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 170 ms 18992 KB Output is correct
40 Correct 196 ms 18932 KB Output is correct
41 Correct 89 ms 13868 KB Output is correct
42 Correct 16 ms 5876 KB Output is correct
43 Correct 2 ms 3412 KB Output is correct
44 Correct 2 ms 3412 KB Output is correct
45 Correct 3 ms 3432 KB Output is correct
46 Correct 3 ms 3432 KB Output is correct
47 Correct 2 ms 3424 KB Output is correct
48 Correct 3 ms 3412 KB Output is correct
49 Correct 3 ms 3412 KB Output is correct
50 Correct 3 ms 3432 KB Output is correct
51 Correct 3 ms 3432 KB Output is correct
52 Correct 3 ms 3412 KB Output is correct
53 Correct 3 ms 3432 KB Output is correct
54 Correct 2 ms 3412 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 2 ms 3412 KB Output is correct
57 Correct 208 ms 13400 KB Output is correct
58 Correct 261 ms 13408 KB Output is correct
59 Correct 220 ms 13512 KB Output is correct
60 Correct 253 ms 13592 KB Output is correct
61 Correct 209 ms 13700 KB Output is correct
62 Correct 203 ms 13668 KB Output is correct
63 Correct 245 ms 13132 KB Output is correct
64 Correct 198 ms 13128 KB Output is correct
65 Correct 194 ms 13432 KB Output is correct
66 Correct 246 ms 13500 KB Output is correct
67 Correct 216 ms 13620 KB Output is correct
68 Correct 199 ms 13656 KB Output is correct
69 Correct 308 ms 13824 KB Output is correct
70 Correct 199 ms 13816 KB Output is correct
71 Correct 2 ms 3412 KB Output is correct
72 Correct 5 ms 3756 KB Output is correct
73 Correct 5 ms 3828 KB Output is correct
74 Correct 6 ms 3860 KB Output is correct
75 Correct 5 ms 3796 KB Output is correct
76 Correct 6 ms 3796 KB Output is correct
77 Correct 5 ms 3828 KB Output is correct
78 Correct 7 ms 3824 KB Output is correct
79 Correct 6 ms 3796 KB Output is correct
80 Correct 216 ms 13624 KB Output is correct
81 Correct 197 ms 13592 KB Output is correct
82 Correct 203 ms 13572 KB Output is correct
83 Correct 247 ms 13700 KB Output is correct
84 Correct 4 ms 3668 KB Output is correct
85 Correct 4 ms 3668 KB Output is correct
86 Correct 4 ms 3668 KB Output is correct
87 Correct 4 ms 3696 KB Output is correct
88 Correct 5 ms 3796 KB Output is correct
89 Correct 4 ms 3700 KB Output is correct
90 Correct 5 ms 3796 KB Output is correct
91 Correct 6 ms 3796 KB Output is correct
92 Correct 5 ms 3796 KB Output is correct
93 Correct 5 ms 3700 KB Output is correct
94 Correct 3 ms 3412 KB Output is correct
95 Correct 2 ms 3412 KB Output is correct
96 Correct 3 ms 3428 KB Output is correct
97 Correct 3 ms 3412 KB Output is correct
98 Correct 2 ms 3420 KB Output is correct
99 Correct 2 ms 3412 KB Output is correct
100 Correct 2 ms 3412 KB Output is correct
101 Correct 2 ms 3412 KB Output is correct
102 Correct 2 ms 3408 KB Output is correct
103 Correct 2 ms 3412 KB Output is correct
104 Correct 14 ms 4940 KB Output is correct
105 Correct 27 ms 7144 KB Output is correct
106 Correct 3 ms 3484 KB Output is correct
107 Correct 66 ms 9452 KB Output is correct
108 Correct 101 ms 11576 KB Output is correct
109 Correct 4 ms 3540 KB Output is correct
110 Correct 133 ms 14640 KB Output is correct
111 Correct 160 ms 16860 KB Output is correct
112 Correct 3 ms 3540 KB Output is correct
113 Correct 238 ms 21484 KB Output is correct
114 Correct 136 ms 12136 KB Output is correct
115 Incorrect 112 ms 12204 KB Output isn't correct
116 Halted 0 ms 0 KB -