Submission #728856

# Submission time Handle Problem Language Result Execution time Memory
728856 2023-04-23T07:50:27 Z Rasoul006 Dreaming (IOI13_dreaming) C++17
14 / 100
73 ms 37052 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++)
    {
        A[i]++,B[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:91:8: warning: unused variable 'sum' [-Wunused-variable]
   91 |     ll sum = 0 ;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 37048 KB Output is correct
2 Correct 65 ms 37052 KB Output is correct
3 Correct 51 ms 32500 KB Output is correct
4 Correct 24 ms 25744 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 40 ms 29136 KB Output is correct
9 Correct 45 ms 31172 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 73 ms 33612 KB Output is correct
12 Correct 70 ms 36024 KB Output is correct
13 Correct 14 ms 23944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 37048 KB Output is correct
2 Correct 65 ms 37052 KB Output is correct
3 Correct 51 ms 32500 KB Output is correct
4 Correct 24 ms 25744 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 40 ms 29136 KB Output is correct
9 Correct 45 ms 31172 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 73 ms 33612 KB Output is correct
12 Correct 70 ms 36024 KB Output is correct
13 Correct 14 ms 23944 KB Output is correct
14 Incorrect 13 ms 23720 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 26836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 37048 KB Output is correct
2 Correct 65 ms 37052 KB Output is correct
3 Correct 51 ms 32500 KB Output is correct
4 Correct 24 ms 25744 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 25 ms 27080 KB Output is correct
7 Correct 15 ms 23800 KB Output is correct
8 Correct 40 ms 29136 KB Output is correct
9 Correct 45 ms 31172 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 73 ms 33612 KB Output is correct
12 Correct 70 ms 36024 KB Output is correct
13 Correct 14 ms 23944 KB Output is correct
14 Incorrect 13 ms 23720 KB Output isn't correct
15 Halted 0 ms 0 KB -