Submission #29795

# Submission time Handle Problem Language Result Execution time Memory
29795 2017-07-20T19:58:02 Z kavun Dreaming (IOI13_dreaming) C++14
32 / 100
76 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)
    return ans;
  if(r.size() == 2) 
    return max(ans,r[0] + r[1] + L);
  else 
    return max(ans,max(r[1] + r[2] + L + L,r[0] + r[1] + L));

}

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 59 ms 13048 KB Output is correct
2 Correct 57 ms 13048 KB Output is correct
3 Correct 41 ms 9464 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6264 KB Output is correct
9 Correct 40 ms 7800 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 53 ms 9416 KB Output is correct
12 Correct 76 ms 11128 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13048 KB Output is correct
2 Correct 57 ms 13048 KB Output is correct
3 Correct 41 ms 9464 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6264 KB Output is correct
9 Correct 40 ms 7800 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 53 ms 9416 KB Output is correct
12 Correct 76 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 2644 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 4 ms 2764 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13048 KB Output is correct
2 Correct 57 ms 13048 KB Output is correct
3 Correct 41 ms 9464 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6264 KB Output is correct
9 Correct 40 ms 7800 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 53 ms 9416 KB Output is correct
12 Correct 76 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 2644 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 4 ms 2764 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6136 KB Output is correct
2 Correct 29 ms 6264 KB Output is correct
3 Correct 44 ms 6212 KB Output is correct
4 Correct 29 ms 6136 KB Output is correct
5 Correct 34 ms 6264 KB Output is correct
6 Correct 34 ms 6648 KB Output is correct
7 Correct 30 ms 6392 KB Output is correct
8 Correct 34 ms 6160 KB Output is correct
9 Correct 34 ms 6132 KB Output is correct
10 Correct 34 ms 6388 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 8 ms 3836 KB Output is correct
13 Correct 8 ms 3964 KB Output is correct
14 Correct 8 ms 3964 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 7 ms 3964 KB Output is correct
19 Correct 7 ms 3836 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 3 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 7 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13048 KB Output is correct
2 Correct 57 ms 13048 KB Output is correct
3 Correct 41 ms 9464 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6264 KB Output is correct
9 Correct 40 ms 7800 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 53 ms 9416 KB Output is correct
12 Correct 76 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 5 ms 2788 KB Output is correct
16 Correct 5 ms 2816 KB Output is correct
17 Correct 4 ms 2688 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 2688 KB Output is correct
21 Correct 5 ms 2788 KB Output is correct
22 Correct 5 ms 2816 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 3 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 59 ms 13048 KB Output is correct
2 Correct 57 ms 13048 KB Output is correct
3 Correct 41 ms 9464 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 28 ms 6264 KB Output is correct
9 Correct 40 ms 7800 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 53 ms 9416 KB Output is correct
12 Correct 76 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 2644 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Incorrect 4 ms 2764 KB Output isn't correct
18 Halted 0 ms 0 KB -