Submission #96734

# Submission time Handle Problem Language Result Execution time Memory
96734 2019-02-11T15:25:44 Z figter001 Dreaming (IOI13_dreaming) C++14
14 / 100
71 ms 11284 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],used[maxn];
vector<int> c;
int sz[maxn],mx,to;

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){
		if(used[s])break;
		int nxt = s;
		int l = 0;
		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;
			}
		}
		if(nxt == s)break;
		sz[s] = all - sz[nxt] + l;
		sz[nxt] -= l;
		used[s] = 1;
		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);
	for(int i=1;i<c.size();i++){
		g[c[i]].push_back({c[0],L});
		g[c[0]].push_back({c[i],L});
	}
	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:72: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 9976 KB Output is correct
2 Correct 53 ms 11128 KB Output is correct
3 Correct 38 ms 9004 KB Output is correct
4 Correct 12 ms 3960 KB Output is correct
5 Correct 10 ms 3452 KB Output is correct
6 Correct 17 ms 4776 KB Output is correct
7 Correct 3 ms 2808 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 38 ms 7672 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 59 ms 8944 KB Output is correct
12 Correct 71 ms 9720 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 3 ms 2808 KB Output is correct
3 Incorrect 5 ms 2808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 9984 KB Output is correct
2 Correct 56 ms 11284 KB Output is correct
3 Correct 45 ms 9020 KB Output is correct
4 Correct 12 ms 4088 KB Output is correct
5 Correct 3 ms 2812 KB Output is correct
6 Correct 3 ms 2808 KB Output is correct
7 Incorrect 4 ms 2808 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 7280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 5 ms 2936 KB Output is correct
3 Correct 5 ms 2992 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 2908 KB Output is correct
4 Correct 46 ms 8136 KB Output is correct
5 Correct 55 ms 9464 KB Output is correct
6 Incorrect 5 ms 2808 KB Output isn't correct
7 Halted 0 ms 0 KB -