답안 #425850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425850 2021-06-13T11:58:27 Z dxz05 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
5 ms 7372 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MP make_pair

const ll INF = 1e18 + 1e8;
const int N = 3e5 + 3e2;

vector<pair<int, int>> g[N];

ll dp[N];
bool processed[N];
int cnt[N];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
    for (int i = 0; i < M; i++){
        g[R[i][0]].emplace_back(R[i][1], L[i]);
        g[R[i][1]].emplace_back(R[i][0], L[i]);
    }

    fill(dp, dp + N, INF);

    priority_queue<pair<ll, int>> pq;
    for (int i = 0; i < K; i++){
        dp[P[i]] = 0;
        pq.push(MP(0, P[i]));
    }

    while (!pq.empty()){
        int v = pq.top().second; pq.pop();
        if (processed[v]) continue;
        processed[v] = true;

        for (auto edge : g[v]){
            int u = edge.first, w = edge.second;

            vector<ll> vec;
            for (auto now : g[u]){
                int j = now.first, w = now.second;
                if (dp[j] != INF) vec.push_back(dp[j] + w);
            }

            if (vec.size() < 2) continue;
            sort(vec.begin(), vec.end());
            if (dp[u] > vec[1]){
                dp[u] = vec[1];
                pq.push(MP(dp[u], u));
            }

        }

    }

    //for (int i = 0; i < N; i++) cout << dp[i] << ' ';

    return dp[0];
}

/**
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1 3
14
*/

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:39:33: warning: unused variable 'w' [-Wunused-variable]
   39 |             int u = edge.first, w = edge.second;
      |                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7280 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7280 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7280 KB Output is correct
3 Incorrect 4 ms 7372 KB Output isn't correct
4 Halted 0 ms 0 KB -