Submission #1022512

# Submission time Handle Problem Language Result Execution time Memory
1022512 2024-07-13T15:55:21 Z amine_aroua Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 14300 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int ,int>>> adj;

vector<int> center;
vector<bool> vis;
int mx = 0;
int y = 0;
int z = 0;
vector<int> nodes;
void dfs1(int x , int p = -1 , int d = 0)
{
    nodes.push_back(x);
    vis[x] = 1;
    if(mx <= d)
    {
        mx = d;
        y = x;
    }
    for(auto [u , c] : adj[x])
    {
        if(u == p)
            continue;
        dfs1(u , x , d + c);
    }
}
vector<pair<int ,int>> par;
vector<int> dist;
void dfs2(int x , int p = -1 , int d = 0)
{
    dist[x] = d;
    if(mx <= d)
    {
        mx = d;
        z = x;
    }
    for(auto [u , c] : adj[x])
    {
        if(u == p)
            continue;
        par[u]= {x , c};
        dfs2(u , x , d + c);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    adj.assign(N , {});
    vis.assign(N , 0);
    for(int i = 0 ; i < M; i++)
    {
        adj[A[i]].push_back({B[i] , T[i]});
        adj[B[i]].push_back({A[i] , T[i]});
    }
    par.assign(N , {-1 , -1});
    dist.assign(N , 0);
    int ans = 0;
    for(int i = 0 ; i < N ; i++)
    {
        if(!vis[i])
        {
            y = 0;
            mx = 0;
            nodes.clear();
            dfs1(i);
            mx = 0;
            z = 0;
            dfs2(y);
            vector<int> a = dist;
            dfs2(z);
            vector<int> b = dist;
            int mn = 2e9;
            for(auto node : nodes)
                mn = min(mn , max(a[node] , b[node]));
            center.push_back(mn);
        }
    }
    sort(center.rbegin(), center.rend());
    if((int)center.size() > 1)
        ans = max(ans , center[0] + center[1] + L);
    if((int)center.size() > 2)
        ans = max(ans , center[1] + center[2] + 2 * L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 14300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 14300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 7596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 14300 KB Output isn't correct
2 Halted 0 ms 0 KB -