Submission #962100

# Submission time Handle Problem Language Result Execution time Memory
962100 2024-04-13T07:03:15 Z serkanrashid Dreaming (IOI13_dreaming) C++11
0 / 100
34 ms 13704 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+5;

struct edge
{
    long long ver,dist;
    edge(){};
    edge(int vi, long long di)
    {
        ver = vi;
        dist = di;
    }
};

int n;

vector<edge> g[MAXN];
long long sub[MAXN],used[MAXN];

long long mind;
vector<long long> comp;

void clear_used()
{
    for(int i = 0; i < n; i++) used[i] = 0;
}

void dfs_dp(int beg, long long gor)
{
    used[beg] = 1;
    long long maxch = max(sub[beg],gor);
    mind = min(mind,maxch);
    long long fir = 0, sec = 0;
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            if(nb.dist+sub[nb.ver] >= fir)
            {
                sec = fir;
                fir = nb.dist+sub[nb.ver];
            }
            else if(nb.dist+sub[nb.ver] >= sec)
            {
                sec = nb.dist+sub[nb.ver];
            }
        }
    }
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            long long new_gor = gor;
            if(nb.dist+sub[nb.ver] == fir) new_gor = max(new_gor,sec);
            else new_gor = max(new_gor,fir);
            new_gor += nb.dist;
            dfs_dp(nb.ver,new_gor);
        }
    }
}

void dfs(int beg)
{
    used[beg] = 1;
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            dfs(nb.ver);
            sub[beg] = max(sub[beg],sub[nb.ver]+nb.dist);
        }
    }
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n = N;
    for(int i = 0; i < M; i++)
    {
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    for(int i = 0; i < N; i++) if(!used[i]) dfs(i);
    clear_used();
    for(int i = 0; i < N; i++)
    {
        if(!used[i])
        {
            mind = 1e9+5;
            dfs_dp(i,0);
            comp.push_back(mind);
        }
    }
    return comp[0]+comp[1]+L;
}
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 13704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 13704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 8056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 13704 KB Output isn't correct
2 Halted 0 ms 0 KB -