답안 #386593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386593 2021-04-07T03:41:25 Z Kepha 악어의 지하 도시 (IOI11_crocodile) C++11
100 / 100
611 ms 47076 KB
// IOI 2011 crocodile
#include <bits/stdc++.h>
#define MX 100000
using namespace std;

int N, M, K;
vector<pair<int, int> > edges[MX + 1];
int dist1[MX + 1], dist2[MX + 1];
bool visited[MX + 1];
priority_queue<pair<int, int> > q;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	for (int i = 0; i < M; i++) {
        int a = R[i][0], b = R[i][1], c = L[i];
        edges[a].push_back({b, c});
        edges[b].push_back({a, c});
    }

	memset(dist1, 0x3f, sizeof(dist1));
    memset(dist2, 0x3f, sizeof(dist2));

    for (int i = 0; i < K; i++) {
        int x = P[i];
        dist1[x] = dist2[x] = 0;
        q.push({0, x});
    }

    while (q.size()) {
        int node = q.top().second;
        q.pop();

        if (visited[node]) continue;
        visited[node] = true;

        for (auto& edge : edges[node]) {
            if (dist2[node] + edge.second < dist1[edge.first]) {
                dist2[edge.first] = dist1[edge.first];
                dist1[edge.first] = dist2[node] + edge.second;
                q.push({-dist2[edge.first], edge.first});
            }
            else if (dist2[node] + edge.second < dist2[edge.first]) {
                dist2[edge.first] = dist2[node] + edge.second;
                q.push({-dist2[edge.first], edge.first});
            }
        }
    }

  	return dist2[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3436 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3564 KB Output is correct
5 Correct 3 ms 3564 KB Output is correct
6 Correct 3 ms 3564 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 3 ms 3564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3436 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3564 KB Output is correct
5 Correct 3 ms 3564 KB Output is correct
6 Correct 3 ms 3564 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 3 ms 3564 KB Output is correct
9 Correct 4 ms 3692 KB Output is correct
10 Correct 3 ms 3436 KB Output is correct
11 Correct 4 ms 3564 KB Output is correct
12 Correct 6 ms 3820 KB Output is correct
13 Correct 5 ms 3948 KB Output is correct
14 Correct 3 ms 3564 KB Output is correct
15 Correct 3 ms 3564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3436 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3564 KB Output is correct
5 Correct 3 ms 3564 KB Output is correct
6 Correct 3 ms 3564 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 3 ms 3564 KB Output is correct
9 Correct 4 ms 3692 KB Output is correct
10 Correct 3 ms 3436 KB Output is correct
11 Correct 4 ms 3564 KB Output is correct
12 Correct 6 ms 3820 KB Output is correct
13 Correct 5 ms 3948 KB Output is correct
14 Correct 3 ms 3564 KB Output is correct
15 Correct 3 ms 3564 KB Output is correct
16 Correct 470 ms 42864 KB Output is correct
17 Correct 94 ms 11784 KB Output is correct
18 Correct 118 ms 13032 KB Output is correct
19 Correct 611 ms 47076 KB Output is correct
20 Correct 296 ms 37484 KB Output is correct
21 Correct 44 ms 7276 KB Output is correct
22 Correct 323 ms 32748 KB Output is correct