Submission #96740

# Submission time Handle Problem Language Result Execution time Memory
96740 2019-02-11T15:38:20 Z figter001 Dreaming (IOI13_dreaming) C++14
14 / 100
90 ms 10232 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = 1e5;

vector<pair<int,int>> g[maxn];
bool vis[maxn];
vector<int> c;
int sz[maxn],mx,to,used[maxn];

void dfs(int u){
	vis[u] = 1;
	for(pair<int,int> cur : g[u]){
		int v = cur.first;
		int w = cur.second;
		if(vis[v])continue;
		sz[v] = w;
		dfs(v);
		sz[u] += sz[v];
	}
}

void find(int s){
	dfs(s);
	int all = sz[s];
	while(1){
		int nxt = s;
		int l = 0,mx = 1;
		for(pair<int,int> cur : g[s]){
			int v = cur.first;
			int w = cur.second;
			if(sz[v] > (all+1) / 2){
				nxt = v;
				l = w;
				mx = max(mx,sz[v]);
			}
		}
		if(used[s]){
			if(used[nxt] < used[s])s = nxt;
			break;
		}
		if(nxt == s)break;
		sz[nxt] -= l;
		sz[s] = all - sz[nxt];
		used[s] = mx;
		s = nxt;
	}
	c.push_back(s);
}

void path(int u,int cost){
	vis[u] = 1;
	if(cost > mx){
		mx = cost;
		to = u;
	}
	for(pair<int,int> cur : g[u]){
		int v = cur.first;
		int w = cur.second;
		if(vis[v])continue;
		path(v,cost + w);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i=0;i<M;i++){
		g[A[i]].push_back({B[i],T[i]});
		g[B[i]].push_back({A[i],T[i]});
	}
	for(int i=0;i<N;i++)
		if(!vis[i])
			find(i);
	// cout << c[0] << ' ';
	for(int i=1;i<c.size();i++){
		// cout << c[i] << ' ';
		g[c[i]].push_back({c[0],L});
		g[c[0]].push_back({c[i],L});
	}
	// printf("\n");
	memset(vis,0,sizeof(vis));
	path(0,0);
	memset(vis,0,sizeof(vis));
	mx = 0;
	path(to,0);
    return mx;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:77:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<c.size();i++){
              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10232 KB Output is correct
2 Correct 74 ms 10232 KB Output is correct
3 Correct 46 ms 8200 KB Output is correct
4 Correct 12 ms 3968 KB Output is correct
5 Correct 11 ms 3456 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 32 ms 5756 KB Output is correct
9 Correct 38 ms 7168 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 7928 KB Output is correct
12 Correct 90 ms 8824 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10232 KB Output is correct
2 Correct 74 ms 10232 KB Output is correct
3 Correct 46 ms 8200 KB Output is correct
4 Correct 12 ms 3968 KB Output is correct
5 Correct 11 ms 3456 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 32 ms 5756 KB Output is correct
9 Correct 38 ms 7168 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 7928 KB Output is correct
12 Correct 90 ms 8824 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 3 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10232 KB Output is correct
2 Correct 74 ms 10232 KB Output is correct
3 Correct 46 ms 8200 KB Output is correct
4 Correct 12 ms 3968 KB Output is correct
5 Correct 11 ms 3456 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 32 ms 5756 KB Output is correct
9 Correct 38 ms 7168 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 7928 KB Output is correct
12 Correct 90 ms 8824 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 3 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 7536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10232 KB Output is correct
2 Correct 74 ms 10232 KB Output is correct
3 Correct 46 ms 8200 KB Output is correct
4 Correct 12 ms 3968 KB Output is correct
5 Correct 11 ms 3456 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 32 ms 5756 KB Output is correct
9 Correct 38 ms 7168 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 7928 KB Output is correct
12 Correct 90 ms 8824 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 5 ms 2816 KB Output is correct
15 Correct 4 ms 2944 KB Output is correct
16 Correct 5 ms 2944 KB Output is correct
17 Incorrect 4 ms 2816 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10232 KB Output is correct
2 Correct 74 ms 10232 KB Output is correct
3 Correct 46 ms 8200 KB Output is correct
4 Correct 12 ms 3968 KB Output is correct
5 Correct 11 ms 3456 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 32 ms 5756 KB Output is correct
9 Correct 38 ms 7168 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 52 ms 7928 KB Output is correct
12 Correct 90 ms 8824 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 3 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -