# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1097757 |
2024-10-08T07:56:27 Z |
Sang |
Valley (BOI19_valley) |
C++17 |
|
162 ms |
51968 KB |
#include<bits/stdc++.h>
using namespace std;
#define _pbrngw_
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int n, s, q, e, in[N], ou[N], timer, marked[N], cost[N], mi[N][20], P[N][20], dis[N], h[N];
vector<ii> G[N];
void dfs(int u, int par){
in[u] = ++timer;
if (marked[u]) cost[u] = 0;
else cost[u] = 1e18;
for (auto v : G[u]){
if (v.fi == par) continue;
dis[v.fi] = dis[u] + v.se;
h[v.fi] = h[u] + 1;
P[v.fi][0] = u;
dfs(v.fi, u);
cost[u] = min(cost[u], cost[v.fi] + v.se);
}
ou[u] = timer;
}
int inside(int u, int v){
return in[u] <= in[v] && in[v] <= ou[u];
}
void dfs2(int u, int par){
for (auto v : G[u]){
if (v.fi == par) continue;
mi[v.fi][0] = cost[u] - dis[u];
// cout << mi[u][0] << "\n";
dfs2(v.fi, u);
}
}
int get(int u, int v){
int k = h[u] - h[v], ans = 1e18;
FORD(i, 17, 0){
if ((k>>i)&1) {
ans = min(ans, mi[u][i]);
u = P[u][i];
}
}
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef _pbrngw_
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
#endif
cin >> n >> s >> q >> e;
vector<pii> edges;
FOR (i, 2, n){
int u, v, w; cin >> u >> v >> w;
G[u].pb({v, w});
G[v].pb({u, w});
edges.pb({w, {u, v}});
}
FOR (i, 1, s){
int x; cin >> x;
marked[x] = 1;
}
memset(mi, 0x3f, sizeof mi);
dfs(e, 0);
dfs2(e, 0);
FOR (j, 1, 17){
FOR (i, 1, n) {
P[i][j] = P[P[i][j-1]][j-1];
mi[i][j] = min(mi[i][j-1], mi[P[i][j-1]][j-1]);
}
}
while (q--){
int p, u; cin >> p >> u;
--p;
if (in[edges[p].se.fi] < in[edges[p].se.se]) swap(edges[p].se.fi, edges[p].se.se);
int v = edges[p].se.fi;
if (!inside(v, u)){
cout << "escaped" << "\n";
continue;
}
int ans = min(cost[u], dis[u] + get(u, v));
if (ans >= 1e18) cout << "oo" << "\n";
else cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18520 KB |
Output is correct |
2 |
Correct |
9 ms |
18524 KB |
Output is correct |
3 |
Correct |
10 ms |
18520 KB |
Output is correct |
4 |
Correct |
10 ms |
18524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18520 KB |
Output is correct |
2 |
Correct |
9 ms |
18524 KB |
Output is correct |
3 |
Correct |
10 ms |
18520 KB |
Output is correct |
4 |
Correct |
10 ms |
18524 KB |
Output is correct |
5 |
Correct |
12 ms |
18780 KB |
Output is correct |
6 |
Correct |
8 ms |
18780 KB |
Output is correct |
7 |
Correct |
8 ms |
19032 KB |
Output is correct |
8 |
Correct |
8 ms |
18780 KB |
Output is correct |
9 |
Correct |
8 ms |
18548 KB |
Output is correct |
10 |
Correct |
8 ms |
18780 KB |
Output is correct |
11 |
Correct |
10 ms |
18780 KB |
Output is correct |
12 |
Correct |
8 ms |
18780 KB |
Output is correct |
13 |
Correct |
9 ms |
18732 KB |
Output is correct |
14 |
Correct |
9 ms |
18780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
46964 KB |
Output is correct |
2 |
Correct |
118 ms |
46616 KB |
Output is correct |
3 |
Correct |
123 ms |
46848 KB |
Output is correct |
4 |
Correct |
162 ms |
48636 KB |
Output is correct |
5 |
Correct |
124 ms |
48892 KB |
Output is correct |
6 |
Correct |
149 ms |
51028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18520 KB |
Output is correct |
2 |
Correct |
9 ms |
18524 KB |
Output is correct |
3 |
Correct |
10 ms |
18520 KB |
Output is correct |
4 |
Correct |
10 ms |
18524 KB |
Output is correct |
5 |
Correct |
12 ms |
18780 KB |
Output is correct |
6 |
Correct |
8 ms |
18780 KB |
Output is correct |
7 |
Correct |
8 ms |
19032 KB |
Output is correct |
8 |
Correct |
8 ms |
18780 KB |
Output is correct |
9 |
Correct |
8 ms |
18548 KB |
Output is correct |
10 |
Correct |
8 ms |
18780 KB |
Output is correct |
11 |
Correct |
10 ms |
18780 KB |
Output is correct |
12 |
Correct |
8 ms |
18780 KB |
Output is correct |
13 |
Correct |
9 ms |
18732 KB |
Output is correct |
14 |
Correct |
9 ms |
18780 KB |
Output is correct |
15 |
Correct |
111 ms |
46964 KB |
Output is correct |
16 |
Correct |
118 ms |
46616 KB |
Output is correct |
17 |
Correct |
123 ms |
46848 KB |
Output is correct |
18 |
Correct |
162 ms |
48636 KB |
Output is correct |
19 |
Correct |
124 ms |
48892 KB |
Output is correct |
20 |
Correct |
149 ms |
51028 KB |
Output is correct |
21 |
Correct |
97 ms |
46216 KB |
Output is correct |
22 |
Correct |
106 ms |
46024 KB |
Output is correct |
23 |
Correct |
114 ms |
46060 KB |
Output is correct |
24 |
Correct |
123 ms |
48156 KB |
Output is correct |
25 |
Correct |
131 ms |
51196 KB |
Output is correct |
26 |
Correct |
108 ms |
46336 KB |
Output is correct |
27 |
Correct |
111 ms |
46336 KB |
Output is correct |
28 |
Correct |
118 ms |
46372 KB |
Output is correct |
29 |
Correct |
129 ms |
47900 KB |
Output is correct |
30 |
Correct |
137 ms |
49560 KB |
Output is correct |
31 |
Correct |
104 ms |
46848 KB |
Output is correct |
32 |
Correct |
103 ms |
46844 KB |
Output is correct |
33 |
Correct |
122 ms |
47040 KB |
Output is correct |
34 |
Correct |
129 ms |
48876 KB |
Output is correct |
35 |
Correct |
122 ms |
51968 KB |
Output is correct |
36 |
Correct |
115 ms |
49380 KB |
Output is correct |