Submission #29797

# Submission time Handle Problem Language Result Execution time Memory
29797 2017-07-20T20:03:20 Z kavun Dreaming (IOI13_dreaming) C++14
32 / 100
112 ms 13048 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
typedef pair<int,int> ii;
vector <ii> adj[100010];
bool mk[100010];
int maxDist, ennd,ans;
ii p[100010];
vector <int> r;

void dfs(int v, int par, int len, int flag)
{
  if(flag)
    mk[v] = true;

  if(len > maxDist)
    {
      maxDist = len;
      ennd = v;
    }

  for(int i = 0; i < adj[v].size(); i++)
    {
      int u = adj[v][i].first;
      if(u == par) continue;
      int weight = adj[v][i].second;
      if(flag)
	p[u] = ii(v,weight);
      dfs(u,v,len+weight,flag);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  for(int i = 0; i < M; i++)
    {
      adj[A[i]].pb(ii(B[i],T[i]));
      adj[B[i]].pb(ii(A[i],T[i]));
    }

  for(int i = 0; i < N; i++)
    {
      if(mk[i]) continue;
      maxDist = -1;
      dfs(i,i,0,0);
      maxDist = -1;
      int first = ennd;
      dfs(first,first,0,1);
      ans = max(ans,maxDist);
      int second = ennd;
      int halfdiam = maxDist / 2;
      int radius = 0;
      for(int ver = second; ver != first; ver = p[ver].first)
	{
	  if(radius + p[ver].second > halfdiam)
	    {
	      radius = max(radius,maxDist - radius);
	      break;
	    }
	  	  radius += p[ver].second;
	}
      r.pb(radius);
    }
    
  sort(r.begin(),r.end());
  reverse(r.begin(),r.end());

 	if (r.size() > 1) ans = max(ans, r[0] + r[1] + L);
	if (r.size() > 2) ans = max(ans, r[1] + r[2] + L + L);
return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int, int)':
dreaming.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < adj[v].size(); i++)
                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 69 ms 13048 KB Output is correct
3 Correct 42 ms 9592 KB Output is correct
4 Correct 11 ms 4224 KB Output is correct
5 Correct 9 ms 3556 KB Output is correct
6 Correct 16 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 31 ms 6264 KB Output is correct
9 Correct 112 ms 7800 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 54 ms 9288 KB Output is correct
12 Correct 73 ms 11128 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 69 ms 13048 KB Output is correct
3 Correct 42 ms 9592 KB Output is correct
4 Correct 11 ms 4224 KB Output is correct
5 Correct 9 ms 3556 KB Output is correct
6 Correct 16 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 31 ms 6264 KB Output is correct
9 Correct 112 ms 7800 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 54 ms 9288 KB Output is correct
12 Correct 73 ms 11128 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 3 ms 2688 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 69 ms 13048 KB Output is correct
3 Correct 42 ms 9592 KB Output is correct
4 Correct 11 ms 4224 KB Output is correct
5 Correct 9 ms 3556 KB Output is correct
6 Correct 16 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 31 ms 6264 KB Output is correct
9 Correct 112 ms 7800 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 54 ms 9288 KB Output is correct
12 Correct 73 ms 11128 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 3 ms 2688 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 6272 KB Output is correct
2 Correct 30 ms 6264 KB Output is correct
3 Correct 26 ms 6140 KB Output is correct
4 Correct 27 ms 6136 KB Output is correct
5 Correct 27 ms 6136 KB Output is correct
6 Correct 33 ms 6784 KB Output is correct
7 Correct 34 ms 6400 KB Output is correct
8 Correct 26 ms 6144 KB Output is correct
9 Correct 26 ms 6132 KB Output is correct
10 Correct 31 ms 6260 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 8 ms 3964 KB Output is correct
13 Correct 8 ms 3964 KB Output is correct
14 Correct 7 ms 3836 KB Output is correct
15 Correct 7 ms 3960 KB Output is correct
16 Correct 7 ms 3836 KB Output is correct
17 Correct 7 ms 3580 KB Output is correct
18 Correct 8 ms 3964 KB Output is correct
19 Correct 7 ms 3836 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2816 KB Output is correct
23 Correct 7 ms 3912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 69 ms 13048 KB Output is correct
3 Correct 42 ms 9592 KB Output is correct
4 Correct 11 ms 4224 KB Output is correct
5 Correct 9 ms 3556 KB Output is correct
6 Correct 16 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 31 ms 6264 KB Output is correct
9 Correct 112 ms 7800 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 54 ms 9288 KB Output is correct
12 Correct 73 ms 11128 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 Correct 5 ms 2816 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 4 ms 2816 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
21 Correct 5 ms 2816 KB Output is correct
22 Correct 5 ms 2944 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Incorrect 4 ms 2688 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 69 ms 13048 KB Output is correct
3 Correct 42 ms 9592 KB Output is correct
4 Correct 11 ms 4224 KB Output is correct
5 Correct 9 ms 3556 KB Output is correct
6 Correct 16 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 31 ms 6264 KB Output is correct
9 Correct 112 ms 7800 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 54 ms 9288 KB Output is correct
12 Correct 73 ms 11128 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 3 ms 2688 KB Output isn't correct
18 Halted 0 ms 0 KB -