답안 #598402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598402 2022-07-18T08:59:32 Z daria 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
0 ms 212 KB
#include "crocodile.h"
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second

const int INF = 1e9+5;

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
// return -1;
 vector<pair<int, int> > adj[n];
 for(int i=0; i<m; ++i){
  adj[r[i][1]].push_back({r[i][0], l[i]});
  adj[r[i][0]].push_back({r[i][1], l[i]});
 }
 vector<pair<int, int> > d(n, {INF, INF});
 vector<bool> vis(n, 0);
 priority_queue<pair<int, int> > pq;
 for(int i=0; i<k; ++i){
  d[p[i]]. f = d[p[i]].s =  0;
  pq.push({0, p[i]});
 }
 while(!pq.empty()){
 /*for(int i=0; i<n; ++i)
  cout << d[i].f << " " << d[i].s << endl;
 cout << endl;*/
  int s = pq.top().s; pq.pop();
  if(vis[s]) continue;
  vis[s] = 1;
  for(auto P : adj[s]){
   int u = P.f, w = P.s;
   if(d[s].s + w < d[u].f){
    d[u].s = d[u].f;
    d[u].f = d[s].s + w;
    pq.push({-d[u].f, u});
   } else if(d[s].s + w == d[u].f)
    d[u].s = d[u].f;
   else if(d[s].s + w < d[u].s)
    d[u].s = d[s].s + w;
  }
 }
 //cout << d[0].s << endl;
 if(d[0].s == INF) return -1;
 return d[0].s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -