This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 vis[MAX_N] = {0};
priority_queue<pii, vector<pii>, greater<pii>> pq;
int dist[MAX_N] = {0};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < K; ++i) {
vis[P[i]] = 2;
}
for(int i = 0; i < M; ++i) {
int a = R[i][0], b = R[i][1];
if(!(vis[a] == 2 && vis[b] == 2)) {
if(!(vis[a] == 2)) swap(a, b);
if(vis[a] == 2) pq.emplace(L[i], b);
}
adj[R[i][0]].emplace_back(R[i][1], L[i]);
adj[R[i][1]].emplace_back(R[i][0], L[i]);
}
while(!pq.empty()) {
int d = pq.top().first, u = pq.top().second;
pq.pop();
if(vis[u] == 2) continue;
else if(vis[u] == 1) {
vis[u] = 2;
dist[u] = d;
for(auto _ : adj[u]) {
int v = _.first, w = _.second;
if(vis[v] == 2) continue;
pq.emplace(d + w, v);
}
}
else vis[u] = 1;
}
return dist[0];
}
// 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;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |