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
65 ms 9976 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

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 65 ms 9976 KB Output is correct
2 Correct 59 ms 9976 KB Output is correct
3 Correct 42 ms 8056 KB Output is correct
4 Correct 12 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 32 ms 5632 KB Output is correct
9 Correct 40 ms 7032 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 56 ms 7800 KB Output is correct
12 Correct 61 ms 8572 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 9976 KB Output is correct
2 Correct 59 ms 9976 KB Output is correct
3 Correct 42 ms 8056 KB Output is correct
4 Correct 12 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 32 ms 5632 KB Output is correct
9 Correct 40 ms 7032 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 56 ms 7800 KB Output is correct
12 Correct 61 ms 8572 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 4 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 9976 KB Output is correct
2 Correct 59 ms 9976 KB Output is correct
3 Correct 42 ms 8056 KB Output is correct
4 Correct 12 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 32 ms 5632 KB Output is correct
9 Correct 40 ms 7032 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 56 ms 7800 KB Output is correct
12 Correct 61 ms 8572 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 4 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 7280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 9976 KB Output is correct
2 Correct 59 ms 9976 KB Output is correct
3 Correct 42 ms 8056 KB Output is correct
4 Correct 12 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 32 ms 5632 KB Output is correct
9 Correct 40 ms 7032 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 56 ms 7800 KB Output is correct
12 Correct 61 ms 8572 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 5 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 65 ms 9976 KB Output is correct
2 Correct 59 ms 9976 KB Output is correct
3 Correct 42 ms 8056 KB Output is correct
4 Correct 12 ms 3840 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 32 ms 5632 KB Output is correct
9 Correct 40 ms 7032 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 56 ms 7800 KB Output is correct
12 Correct 61 ms 8572 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Incorrect 4 ms 2816 KB Output isn't correct
17 Halted 0 ms 0 KB -