제출 #1196348

#제출 시각아이디문제언어결과실행 시간메모리
1196348AMel0n악어의 지하 도시 (IOI11_crocodile)C++20
100 / 100
505 ms47028 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define FOR(N) for(int i = 0; i < N; i++) #define F first #define S second #define all(x) (x).begin(), (x).end() int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { vector<vector<pair<int,int>>> adj(N, vector<pair<int,int>>()); priority_queue<pair<int,int>, vector<pair<int,int>>, greater<>> pq; // second best dist because first best will be blocked, n vector<pair<int,int>> vis(N, {INT_MAX, INT_MAX}); // best, second best vector<bool> seen(N, false); FOR(M) { int a = R[i][0]; int b = R[i][1]; int d = L[i]; adj[a].push_back({b, d}); adj[b].push_back({a, d}); } FOR(K){ vis[P[i]] = {0,0}; pq.push({0, P[i]}); } while(pq.size()){ int d = pq.top().F; int n = pq.top().S; pq.pop(); if (seen[n]) continue; seen[n] = true; //cout << d << ' ' << n << ' ' << vis[n].F << ' ' << vis[n].S << endl; for(auto c: adj[n]) { if (vis[c.F].F > d + c.S) { vis[c.F].S = vis[c.F].F; vis[c.F].F = d + c.S; } else if (vis[c.F].S > d + c.S) { vis[c.F].S = d + c.S; } if (vis[c.F].S != INT_MAX) pq.push({vis[c.F].S, c.F}); //cout << c.F << ' ' << vis[c.F].F << ' '<< vis[c.F].S << endl; } } return vis[0].S; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...