#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
const int N = 100100;
vector<int> vis;
vector<pair<int,int>> dag[N];
int cycle(int v){
vis[v] = 1;
for(auto [u,w]: dag[v]){
if(vis[u] == 0 && cycle(u)) return 1;
if(vis[u] == 1) return 1;
}
vis[v] = 2;
return 0;
};
int travel_plan(int n, int m, int r[][2], int L[], int k, int p[]){
vector<vector<pair<int,int>>> g(n);
for(int i = 0; i < m; i++){
g[r[i][0]].emplace_back(r[i][1], L[i]);
g[r[i][1]].emplace_back(r[i][0], L[i]);
}
vector<int> ext(n);
for(int i = 0; i < k; i++){
ext[p[i]] = 1;
}
vector<ll> dist(n, 1e18);
vector<int> par(n), dep(n);
priority_queue<pair<ll,int>> pq;
pq.emplace(0, 0);
dist[0] = 0;
while(pq.size()){
auto [d,v] = pq.top(); pq.pop();
if(ext[v]) continue;
if(-d > dist[v]) continue;
for(auto [u,w]: g[v]){
if(dist[v] + w < dist[u]){
dist[u] = dist[v] + w;
pq.emplace(-dist[u], u);
par[u] = v;
}
dag[v].emplace_back(u, w);
vis = vector<int>(n);
if(cycle(0)){
dag[v].pop_back();
}
}
}
vector<ll> dp(n, -1);
vector<int> here(n);
function<ll(int)> dfs = [&](int v){
if(dp[v] != -1) return dp[v];
if(ext[v]) return dp[v] = 0;
vector<ll> dists;
for(auto [u,w]: dag[v]){
dists.push_back(dfs(u) + w);
}
if(dists.size() < 2) return dp[v] = (ll) 1e10;
sort(dists.begin(), dists.end());
return dp[v] = dists[1];
};
return (int) dfs(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2796 KB |
Output is correct |
5 |
Correct |
5 ms |
2772 KB |
Output is correct |
6 |
Correct |
4 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
6 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2796 KB |
Output is correct |
5 |
Correct |
5 ms |
2772 KB |
Output is correct |
6 |
Correct |
4 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
6 ms |
2772 KB |
Output is correct |
9 |
Correct |
17 ms |
2900 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2796 KB |
Output is correct |
5 |
Correct |
5 ms |
2772 KB |
Output is correct |
6 |
Correct |
4 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
6 ms |
2772 KB |
Output is correct |
9 |
Correct |
17 ms |
2900 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |