답안 #978941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978941 2024-05-10T04:07:20 Z Panda50O 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
1 ms 4444 KB
#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;

#define MAX_N 50005
#define MAX_M 1000005
#define pii pair<int,int>

const int INF = 2e9+5;
vector<pair<int,int>> adj[MAX_N];
// int N, M, R[MAX_M][2], L[MAX_M], K, P[MAX_N];
int mn_target[MAX_N][2], dist[MAX_N];
bool target[MAX_N], vis[MAX_N];
priority_queue<pii, vector<pii>, greater<pii>> pq;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  for(int i = 0; i < N; ++i) {
    mn_target[i][0] = INF;
    mn_target[i][1] = INF;
    dist[i] = INF;
  }
  for(int i = 0; i < M; ++i) {
    int a = R[i][0], b = R[i][1], c = L[i];
    adj[a].emplace_back(b, c);
    adj[a].emplace_back(b, c);
  }
  for(int i = 0; i < K; ++i) {
    target[P[i]] = true;
  }

  for(int i = 0; i < M; ++i) {
    int a = R[i][0], b = R[i][1], c = L[i];
    if((target[a] && target[b]) || (!target[a] && !target[b])) continue;
    if(target[a]) swap(a, b);
    if(c <= mn_target[a][0]) {
      mn_target[a][1] = mn_target[a][0];
      mn_target[a][0] = c;
    } else if (c < mn_target[a][1]) {
      mn_target[a][1] = c;
    }
  }

  pq.emplace(0, 0);
  dist[0] = 0;
  while(!pq.empty()) {
    auto [d, u] = pq.top();
    pq.pop();
    if(vis[u]) continue;
    vis[u] = true;
    for(auto [v, w] : adj[u]) {
      if(target[v]) continue;
      if(!vis[v] && dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        pq.emplace(dist[v], v);
      }
    }
  }

  int ans = INF;
  for(int i = 0; i < N; ++i) {
    if(target[i]) continue;
    ans = min(ans, dist[i] + mn_target[i][1]);
  }
  return ans;
}


// int main() {
//   ios_base::sync_with_stdio(0); cin.tie(0);
//   int ans;
//   cin >> N >> M >> K;
//   for(int i = 0; i < M; ++i)
//     cin >> R[i][0] >> R[i][1] >> L[i];  
//   for(int i = 0; i < K; ++i)
//     cin >> P[i];

//   ans = travel_plan(N,M,R,L,K,P);
//   cout << ans;
// }



Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:47:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     auto [d, u] = pq.top();
      |          ^
crocodile.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for(auto [v, w] : adj[u]) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -