# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
586778 |
2022-06-30T17:01:23 Z |
blue |
Valley (BOI19_valley) |
C++17 |
|
140 ms |
20452 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
#define sz(x) int(x.size())
const int mx = 100'001;
const ll inf = 1'000'000'000'000'000'000LL;
int N, S, Q, E;
vi A(1+mx), B(1+mx);
vll W(1+mx);
vi edgeind[1+mx];
vll nearshop(1+mx, inf); //distance to closest shop within subtree
vi parent(1+mx, 0);
vi paredge(1+mx, 0);
vll distE(1+mx, 0);
vi depth(1+mx, 0);
vi edgelower(1+mx, 0);
int dfsct = 0;
vi dfsind(1+mx, 0);
vi subtree(1+mx, 1);
void dfs(int u, int p)
{
dfsct++;
dfsind[u] = dfsct;
for(int e : edgeind[u])
{
int v = A[e] + B[e] - u;
ll w = W[e];
if(v == p)
continue;
parent[v] = u;
paredge[v] = e;
edgelower[e] = v;
distE[v] = distE[u] + w;
depth[v] = depth[u] + 1;
dfs(v, u);
nearshop[u] = min(nearshop[u], nearshop[v] + w);
subtree[u] += subtree[v];
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> S >> Q >> E;
for(int e = 1; e <= N-1; e++)
{
cin >> A[e] >> B[e] >> W[e];
edgeind[A[e]].push_back(e);
edgeind[B[e]].push_back(e);
}
for(int x = 1; x <= S; x++)
{
int u;
cin >> u;
nearshop[u] = 0;
}
dfs(E, 0);
for(int q = 1; q <= Q; q++)
{
int I, R;
cin >> I >> R;
bool escape;
if(R == E)
escape = 1;
else
{
int A = edgelower[I];
if(dfsind[A] <= dfsind[R] && dfsind[R] < dfsind[A] + subtree[A])
escape = 0;
else
escape = 1;
}
if(escape)
cout << "escaped\n";
else
cout << 0 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
8244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
8244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
15992 KB |
Output is correct |
2 |
Correct |
113 ms |
15748 KB |
Output is correct |
3 |
Correct |
117 ms |
15712 KB |
Output is correct |
4 |
Correct |
127 ms |
17880 KB |
Output is correct |
5 |
Correct |
105 ms |
17856 KB |
Output is correct |
6 |
Correct |
111 ms |
20452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
8244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |