Submission #332881

# Submission time Handle Problem Language Result Execution time Memory
332881 2020-12-03T23:44:35 Z shrek12357 Dreaming (IOI13_dreaming) C++14
0 / 100
69 ms 15724 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
#include "dreaming.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 

const int MAXN = 1e5 + 5;

ll n, m, l;
vector<pair<ll, ll>> adjList[MAXN];
bool vis[MAXN];
pair<ll, ll> best[MAXN][2];
vector<ll> nodes;
ll mx = 1e12, idx = 0;
ll ans = 0;

void dfs(int src, int p) {
	vis[src] = true;
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		dfs(i.first, src);
		if(best[i.first][0].first + i.second > best[src][0].first){
			best[src][1] = best[src][0];
			best[src][0] = best[i.first][0];
			best[src][0].first += i.second;
			best[src][0].second = i.first;
		}
		else if (best[i.first][0].first + i.second > best[src][1].first) {
			best[src][1] = best[i.first][0];
			best[src][1].first += i.second;
			best[src][1].second = i.first;
		}
	}
}

void cnt(int src, int p, int dist) {
	if (p != -1) {
		if (best[p][0].second != src) {
			if (best[p][0].first + dist > best[src][0].first) {
				best[src][1] = best[src][0];
				best[src][0] = best[p][0];
				best[src][0].first += dist;
				best[src][0].second = p;
			}
			else if (best[p][0].first + dist > best[src][1].first) {
				best[src][1] = best[p][0];
				best[src][1].first += dist;
				best[src][1].second = p;
			}
		}
		else {
			if (best[p][1].first + dist > best[src][0].first) {
				best[src][1] = best[src][0];
				best[src][0] = best[p][1];
				best[src][0].first += dist;
				best[src][0].second = p;
			}
			else if (best[p][1].first + dist > best[src][1].first) {
				best[src][1] = best[p][1];
				best[src][1].first += dist;
				best[src][1].second = p;
			}
		}
	}
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		cnt(i.first, src, i.second);
	}
}

void add(int src, int p) {
	mx = min(mx, best[src][0].first);
	ans = max(ans, best[src][0].first + best[src][1].first);
	if (mx == best[src][0].first) {
		idx = src;
	}
	for (auto i : adjList[src]) {
		if (i.first == p) {
			continue;
		}
		add(i.first, src);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n = N; m = M; l = L;
	for (int i = 0; i < m; i++) {
		adjList[A[i]].push_back({ B[i], T[i] });
		adjList[B[i]].push_back({ A[i], T[i] });
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			mx = 1e12;
			idx = 0;
			dfs(i, -1);
			cnt(i, -1, 0);
			add(i, -1);
			nodes.push_back(mx);
		}
	}
	//for (int i = 0; i < n; i++) {
	//	cout << i << " " << best[i]->first << endl;
	//}
	//cout << ans << endl;
	sort(nodes.begin(), nodes.end());
	reverse(nodes.begin(), nodes.end());
	ans = max(ans, nodes[0] + l + nodes[1]);
	ans = max(ans, nodes[1] + l + l + nodes[2]);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15724 KB Output is correct
2 Correct 65 ms 15340 KB Output is correct
3 Correct 42 ms 12908 KB Output is correct
4 Correct 9 ms 4588 KB Output is correct
5 Correct 8 ms 3948 KB Output is correct
6 Correct 16 ms 5740 KB Output is correct
7 Incorrect 2 ms 2796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15724 KB Output is correct
2 Correct 65 ms 15340 KB Output is correct
3 Correct 42 ms 12908 KB Output is correct
4 Correct 9 ms 4588 KB Output is correct
5 Correct 8 ms 3948 KB Output is correct
6 Correct 16 ms 5740 KB Output is correct
7 Incorrect 2 ms 2796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15724 KB Output is correct
2 Correct 65 ms 15340 KB Output is correct
3 Correct 42 ms 12908 KB Output is correct
4 Correct 9 ms 4588 KB Output is correct
5 Correct 8 ms 3948 KB Output is correct
6 Correct 16 ms 5740 KB Output is correct
7 Incorrect 2 ms 2796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8688 KB Output is correct
2 Correct 30 ms 8684 KB Output is correct
3 Correct 30 ms 8688 KB Output is correct
4 Correct 30 ms 8684 KB Output is correct
5 Correct 31 ms 8708 KB Output is correct
6 Correct 31 ms 9452 KB Output is correct
7 Correct 31 ms 8944 KB Output is correct
8 Correct 29 ms 8580 KB Output is correct
9 Correct 33 ms 8552 KB Output is correct
10 Correct 30 ms 8932 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 8 ms 5476 KB Output is correct
13 Correct 12 ms 6244 KB Output is correct
14 Correct 8 ms 5220 KB Output is correct
15 Correct 8 ms 5604 KB Output is correct
16 Correct 7 ms 5092 KB Output is correct
17 Correct 7 ms 4196 KB Output is correct
18 Correct 8 ms 6372 KB Output is correct
19 Correct 7 ms 5092 KB Output is correct
20 Incorrect 2 ms 2668 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15724 KB Output is correct
2 Correct 65 ms 15340 KB Output is correct
3 Correct 42 ms 12908 KB Output is correct
4 Correct 9 ms 4588 KB Output is correct
5 Correct 8 ms 3948 KB Output is correct
6 Correct 16 ms 5740 KB Output is correct
7 Incorrect 2 ms 2796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15724 KB Output is correct
2 Correct 65 ms 15340 KB Output is correct
3 Correct 42 ms 12908 KB Output is correct
4 Correct 9 ms 4588 KB Output is correct
5 Correct 8 ms 3948 KB Output is correct
6 Correct 16 ms 5740 KB Output is correct
7 Incorrect 2 ms 2796 KB Output isn't correct
8 Halted 0 ms 0 KB -