답안 #958812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958812 2024-04-06T18:35:24 Z dpsaveslives 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
3 ms 6748 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int MAXN = 1e5+10;
vector<pair<int,int>> adj[MAXN];
int travel_plan(int N,int M,int (*R)[2],int *L,int K,int *P){
    for(int i = 0;i<M;++i){
        int u = R[i][0], v = R[i][1], w = L[i];
        adj[u].push_back({v,w}); adj[v].push_back({u,w});
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    vector<vector<int>> dist(N);
    for(int i = 0;i<K;++i){
        pq.push({0,P[i]});
        dist[P[i]].push_back(0); dist[P[i]].push_back(0);
    }
    while(!pq.empty()){
        int cd = pq.top().f, u = pq.top().s; pq.pop();
        for(auto p : adj[u]){
            int v = p.f, w = p.s;
            if(dist[v].size() == 0){
                dist[v].push_back(dist[u][1]+w);
                //pq.push({cd+w,v});
            }
            else if(dist[v].size() == 1){
                dist[v].push_back(dist[u][1]+w);
                sort(dist[v].begin(),dist[v].end());
                pq.push({dist[v][1],v});
            }
            else{
                if(dist[u][1]+w < dist[v][0]){
                    dist[v][1] = dist[v][0];
                    dist[v][0] = dist[u][1]+w;
                    pq.push({dist[v][0],v});
                }
                else if(dist[u][1]+w < dist[v][1]){
                    dist[v][1] = dist[u][1]+w;
                    pq.push({dist[v][1],v});
                }
            }
        }
    }
    return dist[0][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:19:13: warning: unused variable 'cd' [-Wunused-variable]
   19 |         int cd = pq.top().f, u = pq.top().s; pq.pop();
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -