답안 #914311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914311 2024-01-21T15:23:17 Z Ninedesu 꿈 (IOI13_dreaming) C++14
0 / 100
18 ms 4040 KB
#include "dreaming.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,int>
using namespace std;

const int N=2001;
ll a,adis,b,bdis,c,cdis;
ll dis[N],dis2[N],dis3[N];
bool chk;
bitset<N>vis;
vector<int>center;
vector<pii>adj[N];

void dfs1(int u,int p,bool boo){
    vis[u]=true;
    if(!boo&&dis[u]>adis){
        a=u;
        adis=dis[u];
    }
    else if(boo&&dis[u]>bdis){
        b=u;
        bdis=dis[u];
    }
    for(pii wv:adj[u]){
        ll w=wv.first;
        int v=wv.second;
        if(v==p)continue;
        dis[v]=dis[u]+w;
        dfs1(v,u,boo);
    }
}

void dfs2(int u,int p){
    if(u==a){
        chk=true;
        return ;
    }
    for(pii wv:adj[u]){
        int v=wv.second;
        if(v==p)continue;
        dfs2(v,u);
        if(chk){
            if(max(dis[u],bdis-dis[u])<cdis){
                c=u;
                cdis=max(dis[u],bdis-dis[u]);
            }
            return ;
        }
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0; i<M; i++){
        adj[A[i]].push_back({T[i],B[i]});
        adj[B[i]].push_back({T[i],A[i]});
    }
    ll mx=0,smx=0;
    for(int i=0; i<N; i++){
        if(vis[i])continue;
        a=i,b=i,c=i;
        adis=0,bdis=0,cdis=LLONG_MAX;
        chk=false;
        dis[i]=0;
        dfs1(i,-1,0);
        dis[a]=0;
        dfs1(a,-1,1);
        dfs2(b,-1);
        if(a==b)cdis=0;
        if(cdis>mx)smx=mx,mx=cdis;
        else if(cdis>smx) smx=cdis;
    }

    return mx+smx+L;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 4040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 4040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 4040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -