#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 5, oo = 1e18;
int n, s, q, e, dd[N], dist[N];
int ans;
vector<ii> g[N];
struct EDGE
{
int u, v, c;
} edge[N];
bool vst[N];
void dfs(int u)
{
if(dd[u]) ans = min(ans, dist[u]);
vst[u] = 1;
for(auto &[v, c] : g[u])
{
if(vst[v]) continue;
dist[v] = dist[u] + c;
dfs(v);
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> s >> q >> e;
for(int i = 1; i < n; i++)
{
int u, v, c; cin >> u >> v >> c;
edge[i] = {u, v, c};
g[u].push_back({v, c});
g[v].push_back({u, c});
}
for(int i = 1; i <= s; i++)
{
int u; cin >> u;
dd[u] = 1;
}
while(q--)
{
int i, r; cin >> i >> r;
for(int j = 1; j <= n; j++){
g[j].clear();
vst[j] = 0;
dist[j] = oo;
}
for(int j = 1; j < n; j++)
{
if(j == i) continue;
g[edge[j].u].push_back({edge[j].v, edge[j].c});
g[edge[j].v].push_back({edge[j].u, edge[j].c});
}
ans = oo;
dist[r] = 0;
dfs(r);
if(vst[e])
cout << "escaped\n";
else
{
if(ans == oo) cout << "oo\n";
else cout << ans << '\n';
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
valley.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main()
| ^~~~
# | 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... |