Submission #728450

# Submission time Handle Problem Language Result Execution time Memory
728450 2023-04-22T12:23:09 Z Rasoul006 Dreaming (IOI13_dreaming) C++17
24 / 100
109 ms 37972 KB
#include "dreaming.h"

#include <bits/stdc++.h>

#define endl "\n"

#define F first

#define S second

#define pb push_back

typedef long long ll;

using namespace std;

const int N = 1e6+5;

const long long oo = 1e18 ;

vector <pair <ll,ll>> v[N] ;

ll n , m , ans , best , mx , dis[N] , dis2[N] ;

bool vis[N] ;

void dfs (ll u , ll p , ll cost)
{
    dis[u] = cost ;
    vis[u] = true ;

    for (auto it : v[u])
    {
        if (it.F != p)
            dfs(it.F , u , cost + it.S);
    }
}

bool dfs2 (ll u , ll p , ll cost , ll gol)
{
    bool is = false ;

    for (auto it : v[u])
    {
        if (it.F != p)
            is |= dfs2(it.F , u , cost + it.S , gol) ;
    }

    is |= (u == gol) ;
    if (is)
        best = min (best , max(cost , mx-cost)) ;

    return is ;
}

ll p1 , p2 ;

ll get (ll p)
{
    mx = 0 ;
    for (int i = 1 ; i<=n ; i++)
        dis[i] = 0 ;

    dfs(p , p , 0) ;

    for (int i = 1 ; i<=n ; i++)
    {
        if (dis[i] >= mx)
            p1 = i , mx = dis[i] ;
        dis[i] = 0 ;
    }

    mx = 0 ;
    dfs(p1 , p1 , 0) ;
    for (int i = 1 ; i<=n ; i++)
    {
        if (dis[i] >= mx)
            p2 = i , mx = dis[i] ;
    }

    best = oo ;
    dfs2(p1 , p1 , 0 , p2) ;
    return best ;
}


int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    n = N ; m = M ;

    ll sum = 0 ;

    for (int i = 0 ; i<m ; i++)
    {
        v[B[i]].pb({A[i] , T[i]});
        v[A[i]].pb({B[i] , T[i]});
    }

    ans += get(1) ;

    ll bans = mx ;

    for (int i = 1 ; i<=n ; i++)
    {
        if (!vis[i])
        {
            ans += get(i) ;
            break ;
        }
    }

    bans = max(bans , mx) ;

    return max(bans , ans + L) ;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:92:8: warning: unused variable 'sum' [-Wunused-variable]
   92 |     ll sum = 0 ;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 55 ms 37096 KB Output is correct
2 Correct 59 ms 37972 KB Output is correct
3 Correct 41 ms 33460 KB Output is correct
4 Correct 22 ms 25940 KB Output is correct
5 Correct 20 ms 25044 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 33 ms 29132 KB Output is correct
9 Correct 45 ms 31208 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 73 ms 33268 KB Output is correct
12 Correct 102 ms 35736 KB Output is correct
13 Correct 17 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23824 KB Output is correct
2 Correct 13 ms 23924 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23720 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 12 ms 23792 KB Output is correct
7 Correct 15 ms 23768 KB Output is correct
8 Correct 13 ms 23780 KB Output is correct
9 Correct 14 ms 23776 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 13 ms 23732 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 14 ms 23764 KB Output is correct
17 Correct 14 ms 23764 KB Output is correct
18 Correct 12 ms 23796 KB Output is correct
19 Correct 13 ms 23796 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 15 ms 23792 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 37096 KB Output is correct
2 Correct 59 ms 37972 KB Output is correct
3 Correct 41 ms 33460 KB Output is correct
4 Correct 22 ms 25940 KB Output is correct
5 Correct 20 ms 25044 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 33 ms 29132 KB Output is correct
9 Correct 45 ms 31208 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 73 ms 33268 KB Output is correct
12 Correct 102 ms 35736 KB Output is correct
13 Correct 17 ms 23888 KB Output is correct
14 Correct 12 ms 23824 KB Output is correct
15 Correct 13 ms 23924 KB Output is correct
16 Correct 12 ms 23784 KB Output is correct
17 Correct 12 ms 23720 KB Output is correct
18 Correct 13 ms 23792 KB Output is correct
19 Correct 12 ms 23792 KB Output is correct
20 Correct 15 ms 23768 KB Output is correct
21 Correct 13 ms 23780 KB Output is correct
22 Correct 14 ms 23776 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23732 KB Output is correct
27 Correct 13 ms 23800 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 14 ms 23764 KB Output is correct
30 Correct 14 ms 23764 KB Output is correct
31 Correct 12 ms 23796 KB Output is correct
32 Correct 13 ms 23796 KB Output is correct
33 Correct 13 ms 23764 KB Output is correct
34 Correct 15 ms 23792 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 14 ms 23764 KB Output is correct
38 Correct 14 ms 23744 KB Output is correct
39 Correct 76 ms 37860 KB Output is correct
40 Correct 55 ms 37780 KB Output is correct
41 Correct 42 ms 33228 KB Output is correct
42 Correct 21 ms 25948 KB Output is correct
43 Correct 14 ms 23764 KB Output is correct
44 Correct 14 ms 23840 KB Output is correct
45 Correct 13 ms 23788 KB Output is correct
46 Correct 14 ms 23764 KB Output is correct
47 Correct 15 ms 23764 KB Output is correct
48 Correct 13 ms 23764 KB Output is correct
49 Correct 16 ms 23812 KB Output is correct
50 Correct 13 ms 23764 KB Output is correct
51 Correct 13 ms 23764 KB Output is correct
52 Correct 12 ms 23704 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 12 ms 23764 KB Output is correct
55 Correct 15 ms 23764 KB Output is correct
56 Correct 17 ms 23780 KB Output is correct
57 Correct 92 ms 32476 KB Output is correct
58 Correct 89 ms 32500 KB Output is correct
59 Correct 82 ms 32264 KB Output is correct
60 Correct 108 ms 32328 KB Output is correct
61 Correct 109 ms 32264 KB Output is correct
62 Correct 76 ms 32284 KB Output is correct
63 Incorrect 67 ms 31936 KB Output isn't correct
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 26944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23824 KB Output is correct
2 Correct 13 ms 23924 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23720 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 12 ms 23792 KB Output is correct
7 Correct 15 ms 23768 KB Output is correct
8 Correct 13 ms 23780 KB Output is correct
9 Correct 14 ms 23776 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 13 ms 23732 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 14 ms 23764 KB Output is correct
17 Correct 14 ms 23764 KB Output is correct
18 Correct 12 ms 23796 KB Output is correct
19 Correct 13 ms 23796 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 15 ms 23792 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23744 KB Output is correct
26 Correct 13 ms 23892 KB Output is correct
27 Incorrect 16 ms 23892 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 37096 KB Output is correct
2 Correct 59 ms 37972 KB Output is correct
3 Correct 41 ms 33460 KB Output is correct
4 Correct 22 ms 25940 KB Output is correct
5 Correct 20 ms 25044 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 33 ms 29132 KB Output is correct
9 Correct 45 ms 31208 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 73 ms 33268 KB Output is correct
12 Correct 102 ms 35736 KB Output is correct
13 Correct 17 ms 23888 KB Output is correct
14 Correct 12 ms 23824 KB Output is correct
15 Correct 13 ms 23924 KB Output is correct
16 Correct 12 ms 23784 KB Output is correct
17 Correct 12 ms 23720 KB Output is correct
18 Correct 13 ms 23792 KB Output is correct
19 Correct 12 ms 23792 KB Output is correct
20 Correct 15 ms 23768 KB Output is correct
21 Correct 13 ms 23780 KB Output is correct
22 Correct 14 ms 23776 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23732 KB Output is correct
27 Correct 13 ms 23800 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 14 ms 23764 KB Output is correct
30 Correct 14 ms 23764 KB Output is correct
31 Correct 12 ms 23796 KB Output is correct
32 Correct 13 ms 23796 KB Output is correct
33 Correct 13 ms 23764 KB Output is correct
34 Correct 15 ms 23792 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 14 ms 23764 KB Output is correct
38 Correct 14 ms 23744 KB Output is correct
39 Correct 76 ms 37860 KB Output is correct
40 Correct 55 ms 37780 KB Output is correct
41 Correct 42 ms 33228 KB Output is correct
42 Correct 21 ms 25948 KB Output is correct
43 Correct 14 ms 23764 KB Output is correct
44 Correct 14 ms 23840 KB Output is correct
45 Correct 13 ms 23788 KB Output is correct
46 Correct 14 ms 23764 KB Output is correct
47 Correct 15 ms 23764 KB Output is correct
48 Correct 13 ms 23764 KB Output is correct
49 Correct 16 ms 23812 KB Output is correct
50 Correct 13 ms 23764 KB Output is correct
51 Correct 13 ms 23764 KB Output is correct
52 Correct 12 ms 23704 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 12 ms 23764 KB Output is correct
55 Correct 15 ms 23764 KB Output is correct
56 Correct 17 ms 23780 KB Output is correct
57 Correct 92 ms 32476 KB Output is correct
58 Correct 89 ms 32500 KB Output is correct
59 Correct 82 ms 32264 KB Output is correct
60 Correct 108 ms 32328 KB Output is correct
61 Correct 109 ms 32264 KB Output is correct
62 Correct 76 ms 32284 KB Output is correct
63 Incorrect 67 ms 31936 KB Output isn't correct
64 Halted 0 ms 0 KB -