이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
using namespace std;
const int maxN = 100005;
const ll INF = 1e17;
vector<pair<int,int>> adj[maxN];
vector<int> d(maxN, 0);
vector<ll> ans(maxN, INF);
ll solve(int src){
d[src] = 1;
priority_queue<ll> q; //The smallest two
for (pair<int,int> v : adj[src]) {
if (d[v.s] == 0) {
ll x = solve(v.s); //Recursively keep going
if (q.size() < 2) {
q.push(v.f+x);
}
else {
if (v.f+x < q.top()) {
q.pop();
q.push(v.f+x);
}
}
}
else if (d[v.s] == 1) { //Don't want to backtrack
continue;
}
else { //We already processed it
ll x = ans[v.s];
if (q.size() < 2) {
q.push(v.f+x);
}
else {
if (v.f+x<q.top()) {
q.pop();
q.push(v.f+x);
}
}
}
}
if (q.size() < 2) ans[src] = INF;
else ans[src] = q.top();
d[src] = 2;
return ans[src];
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
for (int i=0; i<m; i++) {
int a = r[i][0], b = r[i][1], w = l[i];
adj[a].push_back({w,b});
adj[b].push_back({w,a});
}
for (int i=0; i<k; i++) {
ans[p[i]] = 0;
d[p[i]]= 2;
}
return solve(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |