#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001001001
#define MOD 1000000007
bool visited[100001],cut[100001];
vector<pair<int,int>>adj[100001];
ll dis[100001];
priority_queue<pair<ll,ll>>pq; //-dis, node
void dijkstra(int K, int P[]){
for (int i=0;i<K;i++){
cut[P[i]]=true;
dis[P[i]]=0;
pq.push({0,P[i]});
}
while (!pq.empty()){
ll d=-pq.top().first;
int cur=pq.top().second;
pq.pop();
if (!cut[cur]){
cut[cur]=true;
continue;
}
if (visited[cur])
continue;
visited[cur]=true;
dis[cur]=d;
for (auto x:adj[cur]){
if (!visited[x.first])
pq.push({-(d+x.second),x.first});
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for (int i=0;i<M;i++){
adj[R[i][0]].push_back({R[i][1],L[i]});
adj[R[i][1]].push_back({R[i][0],L[i]});
}
for (int i=0;i<N;i++)
dis[i]=INF;
dijkstra(K,P);
return dis[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
4 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
4 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
3192 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
5 ms |
2808 KB |
Output is correct |
12 |
Correct |
9 ms |
3576 KB |
Output is correct |
13 |
Correct |
9 ms |
3576 KB |
Output is correct |
14 |
Correct |
4 ms |
2808 KB |
Output is correct |
15 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
4 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
3192 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
5 ms |
2808 KB |
Output is correct |
12 |
Correct |
9 ms |
3576 KB |
Output is correct |
13 |
Correct |
9 ms |
3576 KB |
Output is correct |
14 |
Correct |
4 ms |
2808 KB |
Output is correct |
15 |
Correct |
5 ms |
2808 KB |
Output is correct |
16 |
Correct |
805 ms |
72740 KB |
Output is correct |
17 |
Correct |
99 ms |
13944 KB |
Output is correct |
18 |
Correct |
123 ms |
15452 KB |
Output is correct |
19 |
Correct |
921 ms |
75860 KB |
Output is correct |
20 |
Correct |
534 ms |
66128 KB |
Output is correct |
21 |
Correct |
51 ms |
7800 KB |
Output is correct |
22 |
Correct |
517 ms |
46752 KB |
Output is correct |