Submission #546830

# Submission time Handle Problem Language Result Execution time Memory
546830 2022-04-08T15:19:06 Z lovrot Dreaming (IOI13_dreaming) C++11
18 / 100
129 ms 17648 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 = 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], v;
vector<int> used; 
set<int> s;

bool comp(pii a, pii b){
	return a.Y > b.Y;	
}

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;
 	
		v.pb(res);

		it++;
	}
 	
 	sort(v.begin(), v.end(), comp);

	int ret = v[0].Y;
	if(v.size() > 1)
		ret = max(ret, v[0].Y + v[1].Y + l);
	if(v.size() > 2)
		ret = max(ret, v[1].Y + v[2].Y + l * 2);
	return ret;
}
/*
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 Incorrect 129 ms 17648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 17648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 11468 KB Output is correct
2 Correct 89 ms 11464 KB Output is correct
3 Correct 102 ms 11472 KB Output is correct
4 Correct 93 ms 11500 KB Output is correct
5 Correct 92 ms 11460 KB Output is correct
6 Correct 87 ms 12472 KB Output is correct
7 Correct 79 ms 11776 KB Output is correct
8 Correct 78 ms 11260 KB Output is correct
9 Correct 86 ms 11232 KB Output is correct
10 Correct 101 ms 11724 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 35 ms 10824 KB Output is correct
13 Correct 35 ms 10956 KB Output is correct
14 Correct 31 ms 10828 KB Output is correct
15 Correct 32 ms 10924 KB Output is correct
16 Correct 39 ms 10752 KB Output is correct
17 Correct 40 ms 10768 KB Output is correct
18 Correct 40 ms 10968 KB Output is correct
19 Correct 33 ms 10792 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 3668 KB Output is correct
23 Correct 32 ms 10788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 17648 KB Output isn't correct
2 Halted 0 ms 0 KB -