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
63 ms 10364 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

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
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 58 ms 10364 KB Output is correct
2 Correct 55 ms 10360 KB Output is correct
3 Correct 41 ms 8312 KB Output is correct
4 Correct 12 ms 3960 KB Output is correct
5 Correct 9 ms 3576 KB Output is correct
6 Correct 17 ms 4524 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 32 ms 5880 KB Output is correct
9 Correct 41 ms 7348 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 52 ms 8056 KB Output is correct
12 Correct 63 ms 8952 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2808 KB Output is correct
3 Incorrect 4 ms 2808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 10360 KB Output is correct
2 Correct 59 ms 10360 KB Output is correct
3 Correct 39 ms 8284 KB Output is correct
4 Correct 15 ms 3960 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Incorrect 5 ms 2808 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 7664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2812 KB Output is correct
2 Correct 5 ms 2936 KB Output is correct
3 Correct 5 ms 2936 KB Output is correct
4 Incorrect 4 ms 2808 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2936 KB Output is correct
3 Correct 5 ms 2980 KB Output is correct
4 Correct 48 ms 7516 KB Output is correct
5 Correct 62 ms 8824 KB Output is correct
6 Incorrect 4 ms 2808 KB Output isn't correct
7 Halted 0 ms 0 KB -