답안 #984922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984922 2024-05-17T08:22:26 Z 54skyxenon 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
10 ms 9820 KB
// https://oj.uz/problem/view/IOI11_crocodile

/** Needed for linking!!! */
#include "crocodile.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF (ll)1e18

vector<map<int, int>> graph;
vector<bool> is_exit;
vector<bool> visited;

int dfs(int curr) {
    if (is_exit[curr]) {
        return 0;
    }

    vector<ll> distances;
    for (auto [nei, weight] : graph[curr]) {
        if (!visited[nei]) {
            visited[nei] = true;
            distances.push_back(weight + dfs(nei));
        }
    }

    sort(distances.begin(), distances.end());

    if (distances.size() < 2) {
        throw runtime_error("Oops");
    }

    return distances[1];
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    graph.resize(N);
    is_exit.resize(N);
    visited.resize(N);

    for (int i = 0; i < M; i++) {
        graph[R[i][0]][R[i][1]] = graph[R[i][1]][R[i][0]] = L[i];
    }

    for (int i = 0; i < K; i++) {
        is_exit[P[i]] = true;
    }

    try {
        visited[0] = true;
        return dfs(0);
    } catch (...) {
        for (auto [nei, dist] : graph[0]) {
            assert(false);
        }
        return 0;
    }
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:55:19: warning: structured binding declaration set but not used [-Wunused-but-set-variable]
   55 |         for (auto [nei, dist] : graph[0]) {
      |                   ^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Runtime error 10 ms 9820 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Runtime error 10 ms 9820 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -