#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(s) (int)s.size()
#define fi first
#define se second
#define pii pair<int,int>
vector<pair<int,int>> adj[100010];
int n, m, dis[100010];
set<int> good;
bool vis[100010];
int dfs(int s, int p){
multiset<int> S; S.clear();
if(good.count(s)) return dis[s];
if(sz(adj[s])==1) return 1000000000;
//S.insert()
for(auto u : adj[s]){
if(u.fi==p) continue;
S.insert(dfs(u.fi,s));
}
S.erase(S.begin()); return *S.begin();
}
void dijkstra(int s){
for(int i = 0; i <= 100000; i++) dis[i]=1000000000;
dis[s] = 0;
priority_queue<pii,vector<pii>,greater<pii>> pq;
pq.push({0,s});
while(!pq.empty()){
int a = pq.top().se; pq.pop();
if(vis[a]) continue; vis[a] = 1;
for(auto u : adj[a]){
int b = u.fi, w = u.se;
if(dis[b]>dis[a]+w){
dis[b] = dis[a]+w;
pq.push({dis[b],b});
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n = N, m = M;
for(int i = 0; i < n; i++){
int a = R[i][0], b = R[i][1], c = L[i];
adj[a].pb({b,c}), adj[b].pb({a,c});
}
for(int i = 0; i < K; i++) good.insert(P[i]);
dijkstra(0); return dfs(0,-1);
}
Compilation message
crocodile.cpp: In function 'void dijkstra(int)':
crocodile.cpp:33:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
33 | if(vis[a]) continue; vis[a] = 1;
| ^~
crocodile.cpp:33:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
33 | if(vis[a]) continue; vis[a] = 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
3008 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3064 KB |
Output is correct |
7 |
Correct |
3 ms |
3156 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
3008 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3064 KB |
Output is correct |
7 |
Correct |
3 ms |
3156 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3028 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
3008 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Correct |
3 ms |
3156 KB |
Output is correct |
6 |
Correct |
3 ms |
3064 KB |
Output is correct |
7 |
Correct |
3 ms |
3156 KB |
Output is correct |
8 |
Correct |
3 ms |
3156 KB |
Output is correct |
9 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |