이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 1000 + 10;
const ll INF = 1e18;
int n,s,q,root;
int cost[nax];
vector<pi>V[nax];
bool is_shop[nax];
int ban;
bool find_root;
ll dist_to_shop;
void dfs(int x,int p, ll d) {
if(is_shop[x]) {
dist_to_shop = min(dist_to_shop, d);
}
if(x == root) {
find_root = 1;
}
for(auto nbh : V[x]) {
if(nbh.ST != p && ban != nbh.ND) {
dfs(nbh.ST, x, d + cost[nbh.ND]);
}
}
}
int main() {_
cin >> n >> s >> q >> root;
for(int a,b,w,i=1; i<n; ++i) {
cin >> a >> b >> w;
V[a].PB({b,i});
V[b].PB({a,i});
cost[i] = w;
}
for(int a,i=1; i<=s ;++i) {
cin >> a;
is_shop[a] = 1;
}
for(int a,b,i=1; i<=q; ++i) {
cin >> a >> b;
ban = a;
find_root = 0;
dist_to_shop = INF;
dfs(b, 0, 0);
if(find_root) {
cout << "escaped\n";
} else {
if(dist_to_shop != INF) {
cout << dist_to_shop << "\n";
} else {
cout << "oo\n";
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |