# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1094938 |
2024-10-01T01:21:36 Z |
vjudge1 |
Valley (BOI19_valley) |
C++17 |
|
183 ms |
89684 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using ll = long long;
const ll MAXN = 1e6 + 5;
const ll INF = 1e16;
const ll LOG = 30;
#define pll pair <ll, ll>
#define vll vector <ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " " << (x) << endl;
#define lc (pos<<1)
#define rc ((pos<<1)+1)
#define mid ((l+r)>>1)
ll n, s, q, e;
vector <vector <pll> > adj (MAXN);
array <ll, 3> edg [MAXN];
bool b [MAXN];
ll dep [MAXN], dis [MAXN], val [MAXN];
ll anc [MAXN][LOG], spa [MAXN][LOG];
vll lis;
void dfs(ll x, ll px){
anc[x][0] = px;
val[x] = INF;
if(b[x]) val[x] = dis[x];
for(auto nx : adj[x]){
ll y = nx.fi, w = nx.se;
if(y == px) continue;
dep[y] = dep[x] + 1;
dis[y] = dis[x] + w;
dfs(y, x);
val[x] = min(val[x], val[y]);
}
spa[x][0] = val[x] - (2*dis[x]);
if(val[x] == INF) spa[x][0] = INF;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s >> q >> e;
for(ll i = 1; i <= n-1; i++){
ll u, v, w; cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
edg[i] = {u, v, w};
}
for(ll i = 1; i <= s; i++){
ll x; cin >> x; b[x] = 1;
}
dfs(e, 0);
for(ll j = 1; j < LOG; j++){
for(ll i = 1; i <= n; i++){
anc[i][j] = anc[anc[i][j-1]][j-1];
spa[i][j] = min(spa[i][j-1], spa[anc[i][j-1]][j-1]);
}
}
for(ll i = 1; i <= q; i++){
ll ed, x; cin >> ed >> x;
ll u = edg[ed][0], v = edg[ed][1];
if(dep[u] > dep[v]) swap(u, v);
if(dep[x] < dep[v]){
cout << "escaped" << endl;
continue;
}
ll fw = x, mn = spa[fw][0];
for(ll j = LOG-1; j >= 0; j--){
if(dep[anc[fw][j]] >= dep[v]){
mn = min(mn, spa[fw][j]);
fw = anc[fw][j];
mn = min(mn, spa[fw][0]);
}
}
if(fw != v){
cout << "escaped" << endl;
continue;
}
if(mn == INF) cout << "oo" << endl;
else cout << dis[x] + mn << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
24152 KB |
Output is correct |
2 |
Correct |
11 ms |
23996 KB |
Output is correct |
3 |
Correct |
12 ms |
24148 KB |
Output is correct |
4 |
Correct |
16 ms |
24168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
24152 KB |
Output is correct |
2 |
Correct |
11 ms |
23996 KB |
Output is correct |
3 |
Correct |
12 ms |
24148 KB |
Output is correct |
4 |
Correct |
16 ms |
24168 KB |
Output is correct |
5 |
Correct |
11 ms |
24412 KB |
Output is correct |
6 |
Correct |
12 ms |
24412 KB |
Output is correct |
7 |
Correct |
11 ms |
24412 KB |
Output is correct |
8 |
Correct |
11 ms |
24484 KB |
Output is correct |
9 |
Correct |
11 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24580 KB |
Output is correct |
11 |
Correct |
11 ms |
24616 KB |
Output is correct |
12 |
Correct |
12 ms |
24484 KB |
Output is correct |
13 |
Correct |
12 ms |
24412 KB |
Output is correct |
14 |
Correct |
11 ms |
24624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
85332 KB |
Output is correct |
2 |
Correct |
132 ms |
85180 KB |
Output is correct |
3 |
Correct |
142 ms |
85308 KB |
Output is correct |
4 |
Correct |
154 ms |
87316 KB |
Output is correct |
5 |
Correct |
157 ms |
87484 KB |
Output is correct |
6 |
Correct |
183 ms |
89500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
24152 KB |
Output is correct |
2 |
Correct |
11 ms |
23996 KB |
Output is correct |
3 |
Correct |
12 ms |
24148 KB |
Output is correct |
4 |
Correct |
16 ms |
24168 KB |
Output is correct |
5 |
Correct |
11 ms |
24412 KB |
Output is correct |
6 |
Correct |
12 ms |
24412 KB |
Output is correct |
7 |
Correct |
11 ms |
24412 KB |
Output is correct |
8 |
Correct |
11 ms |
24484 KB |
Output is correct |
9 |
Correct |
11 ms |
24412 KB |
Output is correct |
10 |
Correct |
11 ms |
24580 KB |
Output is correct |
11 |
Correct |
11 ms |
24616 KB |
Output is correct |
12 |
Correct |
12 ms |
24484 KB |
Output is correct |
13 |
Correct |
12 ms |
24412 KB |
Output is correct |
14 |
Correct |
11 ms |
24624 KB |
Output is correct |
15 |
Correct |
131 ms |
85332 KB |
Output is correct |
16 |
Correct |
132 ms |
85180 KB |
Output is correct |
17 |
Correct |
142 ms |
85308 KB |
Output is correct |
18 |
Correct |
154 ms |
87316 KB |
Output is correct |
19 |
Correct |
157 ms |
87484 KB |
Output is correct |
20 |
Correct |
183 ms |
89500 KB |
Output is correct |
21 |
Correct |
114 ms |
84564 KB |
Output is correct |
22 |
Correct |
124 ms |
84556 KB |
Output is correct |
23 |
Correct |
130 ms |
84704 KB |
Output is correct |
24 |
Correct |
145 ms |
86864 KB |
Output is correct |
25 |
Correct |
169 ms |
89680 KB |
Output is correct |
26 |
Correct |
133 ms |
85076 KB |
Output is correct |
27 |
Correct |
123 ms |
84584 KB |
Output is correct |
28 |
Correct |
131 ms |
84820 KB |
Output is correct |
29 |
Correct |
143 ms |
86352 KB |
Output is correct |
30 |
Correct |
159 ms |
87888 KB |
Output is correct |
31 |
Correct |
112 ms |
84816 KB |
Output is correct |
32 |
Correct |
131 ms |
84564 KB |
Output is correct |
33 |
Correct |
141 ms |
85080 KB |
Output is correct |
34 |
Correct |
152 ms |
86908 KB |
Output is correct |
35 |
Correct |
168 ms |
89684 KB |
Output is correct |
36 |
Correct |
146 ms |
86868 KB |
Output is correct |