답안 #878606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878606 2023-11-24T22:07:52 Z nikd 꿈 (IOI13_dreaming) C++17
0 / 100
1000 ms 14160 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define MAXN 100000
using namespace std;

int maxpar1[MAXN];
int node1[MAXN];
int maxpar2[MAXN];
int maxlength[MAXN];
bool vis[MAXN];
int tree[MAXN];
int cont;
vector<int> mintree;
vector<pair<int, int>> adj[MAXN];
void dfs1(int v, int p){   
    tree[v]=cont;
    vis[v]=true;
    if(adj[v].size()==1){
        maxpar1[v]=0;
        maxpar2[v]=0;
    }
    else{
        for (auto u : adj[v]) {
            if (u.first != p){
                dfs1(u.first, v);
                if(maxpar1[v]<maxpar1[u.first]+u.second){
                    maxpar1[v]=maxpar1[u.first]+u.second;
                    node1[v]=u.first;
                }
                if(maxpar2[v]<maxpar2[u.first]+u.second){
                    maxpar2[v]=maxpar2[u.first]+u.second;
                }
                
            }
        }
    }
    maxlength[v]=maxpar1[v];
}
void dfs2(int v, int p, int d){   
    vis[v]=true;
    if(v!=p){
        if(node1[p]!=v){
            maxlength[v]=max(maxlength[v], maxpar1[p]+d);
        }
        else{
            maxlength[v]=max(maxlength[v], maxpar2[p]+d);
        }
    }
    for (auto u : adj[v]) {
        if (u.first != p){
            dfs2(u.first, v, u.second);
            
        }
    }
    
}


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({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }
    for(int i = 0; i<N; i++){
        maxpar1[i]=-1;
        maxpar2[i]=-1;
        maxlength[i]=-1;
        vis[i]=false;
    }
    cont =0;
    for(int i =0; i<N; i++){
        if(!vis[i]){
            mintree.push_back(INT_MAX);
            dfs1(i,i);
            cont++;
        }
    }
    for(int i =0; i<N; i++){
        dfs2(i, i, 0);
    }
    int maxbest1=-1;
    int maxbest2=-1;
    int maxbest3=-1;
    for(int i =0; i<N; i++){
        if(maxlength[i]<mintree[tree[i]]){
            mintree[tree[i]]=maxlength[i];
            if(mintree[tree[i]]>maxbest1){
                maxbest1=mintree[tree[i]];
            }
            else if(mintree[tree[i]]>maxbest2){
                maxbest2=mintree[tree[i]];
            }
            else if(mintree[tree[i]]>maxbest3){
                maxbest3=mintree[tree[i]];
            }
        }
    }
    int sol =max(maxbest1+L+maxbest2, maxbest2+maxbest3+2*L);
    return sol;


}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1031 ms 14160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1031 ms 14160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 8412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1031 ms 14160 KB Time limit exceeded
2 Halted 0 ms 0 KB -