Submission #546795

# Submission time Handle Problem Language Result Execution time Memory
546795 2022-04-08T13:45:50 Z lovrot Dreaming (IOI13_dreaming) C++11
47 / 100
306 ms 22968 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 = 200010;
const int INF = 2 * 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 177 ms 20948 KB Output is correct
2 Correct 198 ms 20816 KB Output is correct
3 Correct 87 ms 15928 KB Output is correct
4 Correct 17 ms 8788 KB Output is correct
5 Correct 14 ms 7996 KB Output is correct
6 Correct 31 ms 10016 KB Output is correct
7 Correct 5 ms 6612 KB Output is correct
8 Correct 84 ms 12088 KB Output is correct
9 Correct 82 ms 14060 KB Output is correct
10 Correct 4 ms 6740 KB Output is correct
11 Correct 139 ms 16592 KB Output is correct
12 Correct 207 ms 18892 KB Output is correct
13 Correct 6 ms 6768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 3 ms 6612 KB Output is correct
3 Correct 3 ms 6612 KB Output is correct
4 Correct 4 ms 6608 KB Output is correct
5 Correct 3 ms 6636 KB Output is correct
6 Correct 4 ms 6612 KB Output is correct
7 Correct 4 ms 6612 KB Output is correct
8 Correct 4 ms 6612 KB Output is correct
9 Correct 3 ms 6612 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
11 Correct 4 ms 6636 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 4 ms 6612 KB Output is correct
14 Correct 5 ms 6612 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 4 ms 6612 KB Output is correct
17 Correct 5 ms 6648 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6648 KB Output is correct
23 Correct 3 ms 6612 KB Output is correct
24 Correct 3 ms 6612 KB Output is correct
25 Correct 3 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 20948 KB Output is correct
2 Correct 198 ms 20816 KB Output is correct
3 Correct 87 ms 15928 KB Output is correct
4 Correct 17 ms 8788 KB Output is correct
5 Correct 14 ms 7996 KB Output is correct
6 Correct 31 ms 10016 KB Output is correct
7 Correct 5 ms 6612 KB Output is correct
8 Correct 84 ms 12088 KB Output is correct
9 Correct 82 ms 14060 KB Output is correct
10 Correct 4 ms 6740 KB Output is correct
11 Correct 139 ms 16592 KB Output is correct
12 Correct 207 ms 18892 KB Output is correct
13 Correct 6 ms 6768 KB Output is correct
14 Correct 4 ms 6612 KB Output is correct
15 Correct 3 ms 6612 KB Output is correct
16 Correct 3 ms 6612 KB Output is correct
17 Correct 4 ms 6608 KB Output is correct
18 Correct 3 ms 6636 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6636 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6612 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 4 ms 6612 KB Output is correct
30 Correct 5 ms 6648 KB Output is correct
31 Correct 4 ms 6612 KB Output is correct
32 Correct 4 ms 6612 KB Output is correct
33 Correct 4 ms 6612 KB Output is correct
34 Correct 4 ms 6612 KB Output is correct
35 Correct 3 ms 6648 KB Output is correct
36 Correct 3 ms 6612 KB Output is correct
37 Correct 3 ms 6612 KB Output is correct
38 Correct 3 ms 6612 KB Output is correct
39 Correct 175 ms 20836 KB Output is correct
40 Correct 176 ms 20796 KB Output is correct
41 Correct 87 ms 16176 KB Output is correct
42 Correct 17 ms 8808 KB Output is correct
43 Correct 4 ms 6612 KB Output is correct
44 Correct 3 ms 6612 KB Output is correct
45 Correct 3 ms 6612 KB Output is correct
46 Correct 4 ms 6612 KB Output is correct
47 Correct 5 ms 6592 KB Output is correct
48 Correct 4 ms 6612 KB Output is correct
49 Correct 4 ms 6612 KB Output is correct
50 Correct 4 ms 6612 KB Output is correct
51 Correct 4 ms 6612 KB Output is correct
52 Correct 3 ms 6612 KB Output is correct
53 Correct 4 ms 6612 KB Output is correct
54 Correct 4 ms 6612 KB Output is correct
55 Correct 4 ms 6612 KB Output is correct
56 Correct 4 ms 6612 KB Output is correct
57 Correct 201 ms 15320 KB Output is correct
58 Correct 201 ms 15320 KB Output is correct
59 Correct 306 ms 15432 KB Output is correct
60 Correct 207 ms 15436 KB Output is correct
61 Correct 192 ms 15272 KB Output is correct
62 Correct 249 ms 15340 KB Output is correct
63 Correct 182 ms 14928 KB Output is correct
64 Correct 241 ms 15048 KB Output is correct
65 Correct 217 ms 15048 KB Output is correct
66 Correct 189 ms 15056 KB Output is correct
67 Correct 250 ms 15320 KB Output is correct
68 Correct 232 ms 15304 KB Output is correct
69 Correct 213 ms 15432 KB Output is correct
70 Correct 240 ms 15436 KB Output is correct
71 Correct 4 ms 6552 KB Output is correct
72 Correct 7 ms 6868 KB Output is correct
73 Correct 7 ms 6868 KB Output is correct
74 Correct 6 ms 6868 KB Output is correct
75 Correct 6 ms 6868 KB Output is correct
76 Correct 7 ms 6868 KB Output is correct
77 Correct 6 ms 6868 KB Output is correct
78 Correct 7 ms 6976 KB Output is correct
79 Correct 6 ms 6868 KB Output is correct
80 Correct 230 ms 15384 KB Output is correct
81 Correct 249 ms 15376 KB Output is correct
82 Correct 198 ms 15244 KB Output is correct
83 Correct 227 ms 15316 KB Output is correct
84 Correct 5 ms 6868 KB Output is correct
85 Correct 6 ms 6740 KB Output is correct
86 Correct 6 ms 6868 KB Output is correct
87 Correct 6 ms 6868 KB Output is correct
88 Correct 6 ms 6868 KB Output is correct
89 Correct 6 ms 6868 KB Output is correct
90 Correct 6 ms 6844 KB Output is correct
91 Correct 7 ms 6868 KB Output is correct
92 Correct 7 ms 6868 KB Output is correct
93 Correct 6 ms 6868 KB Output is correct
94 Correct 3 ms 6612 KB Output is correct
95 Correct 4 ms 6612 KB Output is correct
96 Correct 3 ms 6576 KB Output is correct
97 Correct 4 ms 6612 KB Output is correct
98 Correct 4 ms 6612 KB Output is correct
99 Correct 4 ms 6612 KB Output is correct
100 Correct 4 ms 6612 KB Output is correct
101 Correct 5 ms 6556 KB Output is correct
102 Correct 5 ms 6572 KB Output is correct
103 Correct 4 ms 6612 KB Output is correct
104 Correct 16 ms 7892 KB Output is correct
105 Correct 35 ms 10056 KB Output is correct
106 Correct 4 ms 6612 KB Output is correct
107 Correct 71 ms 12100 KB Output is correct
108 Correct 81 ms 13976 KB Output is correct
109 Correct 4 ms 6740 KB Output is correct
110 Correct 130 ms 16620 KB Output is correct
111 Correct 194 ms 18904 KB Output is correct
112 Correct 7 ms 6772 KB Output is correct
113 Correct 260 ms 22968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 15272 KB Output is correct
2 Incorrect 115 ms 15264 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 3 ms 6612 KB Output is correct
3 Correct 3 ms 6612 KB Output is correct
4 Correct 4 ms 6608 KB Output is correct
5 Correct 3 ms 6636 KB Output is correct
6 Correct 4 ms 6612 KB Output is correct
7 Correct 4 ms 6612 KB Output is correct
8 Correct 4 ms 6612 KB Output is correct
9 Correct 3 ms 6612 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
11 Correct 4 ms 6636 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 4 ms 6612 KB Output is correct
14 Correct 5 ms 6612 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 4 ms 6612 KB Output is correct
17 Correct 5 ms 6648 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6648 KB Output is correct
23 Correct 3 ms 6612 KB Output is correct
24 Correct 3 ms 6612 KB Output is correct
25 Correct 3 ms 6612 KB Output is correct
26 Correct 5 ms 6740 KB Output is correct
27 Correct 6 ms 6740 KB Output is correct
28 Correct 7 ms 6920 KB Output is correct
29 Correct 4 ms 6612 KB Output is correct
30 Correct 6 ms 6824 KB Output is correct
31 Correct 7 ms 6884 KB Output is correct
32 Correct 4 ms 6640 KB Output is correct
33 Correct 6 ms 6740 KB Output is correct
34 Correct 7 ms 6868 KB Output is correct
35 Correct 4 ms 6612 KB Output is correct
36 Correct 4 ms 6612 KB Output is correct
37 Correct 3 ms 6612 KB Output is correct
38 Correct 4 ms 6612 KB Output is correct
39 Correct 4 ms 6612 KB Output is correct
40 Incorrect 4 ms 6612 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 20948 KB Output is correct
2 Correct 198 ms 20816 KB Output is correct
3 Correct 87 ms 15928 KB Output is correct
4 Correct 17 ms 8788 KB Output is correct
5 Correct 14 ms 7996 KB Output is correct
6 Correct 31 ms 10016 KB Output is correct
7 Correct 5 ms 6612 KB Output is correct
8 Correct 84 ms 12088 KB Output is correct
9 Correct 82 ms 14060 KB Output is correct
10 Correct 4 ms 6740 KB Output is correct
11 Correct 139 ms 16592 KB Output is correct
12 Correct 207 ms 18892 KB Output is correct
13 Correct 6 ms 6768 KB Output is correct
14 Correct 4 ms 6612 KB Output is correct
15 Correct 3 ms 6612 KB Output is correct
16 Correct 3 ms 6612 KB Output is correct
17 Correct 4 ms 6608 KB Output is correct
18 Correct 3 ms 6636 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6636 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6612 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 4 ms 6612 KB Output is correct
30 Correct 5 ms 6648 KB Output is correct
31 Correct 4 ms 6612 KB Output is correct
32 Correct 4 ms 6612 KB Output is correct
33 Correct 4 ms 6612 KB Output is correct
34 Correct 4 ms 6612 KB Output is correct
35 Correct 3 ms 6648 KB Output is correct
36 Correct 3 ms 6612 KB Output is correct
37 Correct 3 ms 6612 KB Output is correct
38 Correct 3 ms 6612 KB Output is correct
39 Correct 175 ms 20836 KB Output is correct
40 Correct 176 ms 20796 KB Output is correct
41 Correct 87 ms 16176 KB Output is correct
42 Correct 17 ms 8808 KB Output is correct
43 Correct 4 ms 6612 KB Output is correct
44 Correct 3 ms 6612 KB Output is correct
45 Correct 3 ms 6612 KB Output is correct
46 Correct 4 ms 6612 KB Output is correct
47 Correct 5 ms 6592 KB Output is correct
48 Correct 4 ms 6612 KB Output is correct
49 Correct 4 ms 6612 KB Output is correct
50 Correct 4 ms 6612 KB Output is correct
51 Correct 4 ms 6612 KB Output is correct
52 Correct 3 ms 6612 KB Output is correct
53 Correct 4 ms 6612 KB Output is correct
54 Correct 4 ms 6612 KB Output is correct
55 Correct 4 ms 6612 KB Output is correct
56 Correct 4 ms 6612 KB Output is correct
57 Correct 201 ms 15320 KB Output is correct
58 Correct 201 ms 15320 KB Output is correct
59 Correct 306 ms 15432 KB Output is correct
60 Correct 207 ms 15436 KB Output is correct
61 Correct 192 ms 15272 KB Output is correct
62 Correct 249 ms 15340 KB Output is correct
63 Correct 182 ms 14928 KB Output is correct
64 Correct 241 ms 15048 KB Output is correct
65 Correct 217 ms 15048 KB Output is correct
66 Correct 189 ms 15056 KB Output is correct
67 Correct 250 ms 15320 KB Output is correct
68 Correct 232 ms 15304 KB Output is correct
69 Correct 213 ms 15432 KB Output is correct
70 Correct 240 ms 15436 KB Output is correct
71 Correct 4 ms 6552 KB Output is correct
72 Correct 7 ms 6868 KB Output is correct
73 Correct 7 ms 6868 KB Output is correct
74 Correct 6 ms 6868 KB Output is correct
75 Correct 6 ms 6868 KB Output is correct
76 Correct 7 ms 6868 KB Output is correct
77 Correct 6 ms 6868 KB Output is correct
78 Correct 7 ms 6976 KB Output is correct
79 Correct 6 ms 6868 KB Output is correct
80 Correct 230 ms 15384 KB Output is correct
81 Correct 249 ms 15376 KB Output is correct
82 Correct 198 ms 15244 KB Output is correct
83 Correct 227 ms 15316 KB Output is correct
84 Correct 5 ms 6868 KB Output is correct
85 Correct 6 ms 6740 KB Output is correct
86 Correct 6 ms 6868 KB Output is correct
87 Correct 6 ms 6868 KB Output is correct
88 Correct 6 ms 6868 KB Output is correct
89 Correct 6 ms 6868 KB Output is correct
90 Correct 6 ms 6844 KB Output is correct
91 Correct 7 ms 6868 KB Output is correct
92 Correct 7 ms 6868 KB Output is correct
93 Correct 6 ms 6868 KB Output is correct
94 Correct 3 ms 6612 KB Output is correct
95 Correct 4 ms 6612 KB Output is correct
96 Correct 3 ms 6576 KB Output is correct
97 Correct 4 ms 6612 KB Output is correct
98 Correct 4 ms 6612 KB Output is correct
99 Correct 4 ms 6612 KB Output is correct
100 Correct 4 ms 6612 KB Output is correct
101 Correct 5 ms 6556 KB Output is correct
102 Correct 5 ms 6572 KB Output is correct
103 Correct 4 ms 6612 KB Output is correct
104 Correct 16 ms 7892 KB Output is correct
105 Correct 35 ms 10056 KB Output is correct
106 Correct 4 ms 6612 KB Output is correct
107 Correct 71 ms 12100 KB Output is correct
108 Correct 81 ms 13976 KB Output is correct
109 Correct 4 ms 6740 KB Output is correct
110 Correct 130 ms 16620 KB Output is correct
111 Correct 194 ms 18904 KB Output is correct
112 Correct 7 ms 6772 KB Output is correct
113 Correct 260 ms 22968 KB Output is correct
114 Correct 127 ms 15272 KB Output is correct
115 Incorrect 115 ms 15264 KB Output isn't correct
116 Halted 0 ms 0 KB -