#include <bits/stdc++.h>
//#include "crocodile.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef long long ll;
typedef pair<int, int> pii;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int dist[1005];
vector<pii> adj[1005];
bool isExit[1005];
int ans = 1e9;
void dfs(int u, int p){
cout << u << " " << p << '\n';
for(pii e : adj[u]){
int v=e.f;
int w = e.s;
if(v == p)continue;
dist[v] = dist[u] + w;
dfs(v, u);
}
vector<int> children;
for(pii e : adj[u]){
if(e.f != p && isExit[e.f]){
children.pb(dist[e.f]);
}
}
sort(children.begin(), children.end());
if(children.size() >= 2){
ans = min(ans, children[1]);
}
}
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]].pb({R[i][1], L[i]});
adj[R[i][1]].pb({R[i][0], L[i]});
}
for(int i = 0; i < K; i++){
isExit[P[i]] = true;
}
dfs(0, -1);
assert(ans != 1e9);
return (int)ans;
}
/**
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N = 5;
int M = 4;
int R[M][2];
R[0][0] = 0;
R[0][1] = 1;
R[1][0] = 0;
R[1][1] = 2;
R[2][0] = 0;
R[2][1] = 3;
R[3][0] = 3;
R[3][1] = 4;
int L[M];
for(int i = 0; i < M; i++){
L[i] = i;
}
int K = 2;
int P[K];
P[0] = 1;
P[1] = 2;
cout << travel_plan(N, M, R, L, K, P);
}
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |