#include "crocodile.h"
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
using namespace std;
vector<vector<pair<int,int> > >G;
const int INF=2*1e9;
int dp[1005];
void dfs(int nodo,int p){
vi v;
for(auto it : G[nodo]){
if(it.F==p)continue;
dfs(it.F,nodo);
v.pb(dp[it.F]+it.S);
}
sort(v.begin(),v.end());
if(G[nodo].size()==1){
dp[nodo]=0;
}else{
dp[nodo]=v[1];
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
//R[i][0] --- R[i][1] con peso L[i]
G.assign(N+1,vector<pair<int,int> >());
int dis[N+1][2];
for(int i=0;i<=N;i++){
dis[i][0]=dis[i][1]=INF;
}
for(int i=0;i<M;i++){
int a=R[i][0],b=R[i][1],w=L[i];
G[a].pb({b,w});
G[b].pb({a,w});
}
priority_queue<pair<int,int> >q;
for(int i=0;i<K;i++){
dis[P[i]][0]=dis[P[i]][1]=0;
q.push({0,P[i]});
}
vector<bool>vis(N+1,false);
while(!q.empty()){
int nodo=q.top().S;
q.pop();
if(vis[nodo])continue;
vis[nodo]=1;
for(auto it : G[nodo]){
int D=dis[nodo][1];
if(D+it.S<dis[it.F][0]){
dis[it.F][1]=dis[it.F][0];
dis[it.F][0]=D+it.S;
if(dis[it.F][1]!=INF){
q.push({-dis[it.F][1],it.F});
}
}else{
if(D+it.S<dis[it.F][1]){
dis[it.F][1]=D+it.S;
q.push({-dis[it.F][1],it.F});
}
}
}
}
return dis[0][1];
}
/*
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1 3
14
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
4 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
4 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
479 ms |
40036 KB |
Output is correct |
17 |
Correct |
80 ms |
10476 KB |
Output is correct |
18 |
Correct |
100 ms |
11884 KB |
Output is correct |
19 |
Correct |
624 ms |
44864 KB |
Output is correct |
20 |
Correct |
310 ms |
34028 KB |
Output is correct |
21 |
Correct |
39 ms |
4588 KB |
Output is correct |
22 |
Correct |
344 ms |
30188 KB |
Output is correct |