이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <stack>
#include <math.h>
#include "crocodile.h"
#define MAX 1000000001
struct Conn {
    int dest;
    int weight;
};
struct Node {
    std::vector<Conn> connections;
    int optimal_time = -1;
    int getOptimalTime();
};
Node* nodes;
int Node::getOptimalTime() {
    if(optimal_time != -1)
        return optimal_time;
    
    int best_time = MAX, second_best_time = MAX;
    optimal_time = MAX + 1;
    
    for(Conn& conn : connections) {
        int weight = nodes[conn.dest].getOptimalTime() + conn.weight;
        if(weight <= best_time) {
            second_best_time = best_time;
            best_time = weight;
        } else if(weight <= second_best_time)
            second_best_time = weight;
    }
    
    optimal_time = second_best_time;
    return optimal_time;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    nodes = new Node[N];
    
    for(int i = 0; i < M; i++) {
        int a1 = R[i][0], a2 = R[i][1];
        Conn conn;
        conn.weight = L[i];
        
        conn.dest = a2;
        nodes[a1].connections.push_back(conn);
        
        conn.dest = a1;
        nodes[a2].connections.push_back(conn);
    }
    
    for(int i = 0; i < K; i++)
        nodes[P[i]].optimal_time = 0;
    
    int result = nodes[0].getOptimalTime();
    delete[] nodes;
    return result;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |