| Task: | Nautilus |
| Sender: | a256 |
| Submission time: | 2023-04-18 17:13:37 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 0 |
| #2 | RUNTIME ERROR | 0 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #2 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #3 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #4 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #5 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #6 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #7 | RUNTIME ERROR | 0.01 s | 1, 2, 3 | details |
| #8 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #9 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #10 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #11 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #12 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #13 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #14 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #15 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #16 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #17 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #18 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #19 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #20 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #21 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #22 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #23 | RUNTIME ERROR | 0.01 s | 3 | details |
| #24 | RUNTIME ERROR | 0.01 s | 3 | details |
| #25 | RUNTIME ERROR | 0.01 s | 3 | details |
| #26 | RUNTIME ERROR | 0.01 s | 3 | details |
| #27 | RUNTIME ERROR | 0.01 s | 3 | details |
| #28 | RUNTIME ERROR | 0.01 s | 3 | details |
| #29 | RUNTIME ERROR | 0.01 s | 3 | details |
| #30 | RUNTIME ERROR | 0.01 s | 3 | details |
| #31 | RUNTIME ERROR | 0.01 s | 3 | details |
| #32 | RUNTIME ERROR | 0.01 s | 3 | details |
| #33 | RUNTIME ERROR | 0.01 s | 3 | details |
| #34 | RUNTIME ERROR | 0.01 s | 3 | details |
| #35 | RUNTIME ERROR | 0.01 s | 3 | details |
| #36 | RUNTIME ERROR | 0.01 s | 3 | details |
| #37 | RUNTIME ERROR | 0.01 s | 3 | details |
Code
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll LLM=LONG_LONG_MAX;
int N,S,Q,E,shp[(int)2e5],I,D[(int)2e5];
vector<pair<int,pair<ll,int>>> v[(int)2e5];
vector<pair<int,int>> tiet;
vector<int> shops;
int f[(int)2e5][32],z[(int)2e5];
pair<int,ll> h[(int)2e5];
int ylös(int s,int k){
for(;k;k^=(k&-k))
s=f[s][__builtin_ctz(k)+1];
return s;
}
int aye(int a,int b){
if(D[b]>D[a]) swap(a,b);
a=ylös(a,D[a]-D[b]);
if(a==b) return a;
for(int i=31;i;--i){
if(f[a][i]!=f[b][i]){
a=f[a][i];
b=f[b][i];
}
}
return f[a][1];
}
void haku(int s,int p,int d){
D[s]=d;
f[s][0]=s;
f[s][1]=p;
for(int k=2;k<32&&f[s][k-1];++k){
f[s][k]=f[f[s][k-1]][k-1];
}
for(auto u:v[s]){
if(u.first==p) continue;
haku(u.first,s,d+1);
}
}
void haku2(){
priority_queue<pair<pair<ll,int>,pair<int,int>>> q;
for(int s:shops) q.push({{0,s},{s,-1}});
while(q.size()){
auto p=q.top();q.pop();
ll et=-p.first.first;
int u=p.second.first;
if(z[u]) continue;
z[u]=1;
h[u]={p.first.second,et};
for(auto B:v[u]){
if(B.first==p.second.second||B.second.second==I) continue;
q.push({{-et-B.second.first,p.first.second},{B.first,u}});
}
}
}
bool reitillä(int a,int b,int s){
if(s==a||s==b) return true;
int ay=aye(a,b);
if(D[s]<D[ay]) return false;
if(D[a]>D[s]&&ylös(a,D[a]-D[s])==s) return true;
if(D[b]>D[s]&&ylös(b,D[b]-D[s])==s) return true;
return false;
}
bool kaari_reitillä(int a,int b){
int ka=tiet[I-1].first,kb=tiet[I-1].second;
return reitillä(a,b,ka)&&reitillä(a,b,kb);
}
bool ppako(int s){
int a=tiet[I-1].first,b=tiet[I-1].second;
return !(reitillä(s,E,a)&&reitillä(s,E,b));
}
bool pako(int s,int p){
if(s==E) return true;
for(auto u:v[s]){
if(u.first==p||u.second.second==I) continue;
if(pako(u.first,s)) return true;
}
return false;
}
ll etäisyys(int s,int ss){
priority_queue<pair<ll,pair<int,int>>> q;
q.push({0,{s,-1}});
while(q.size()){
auto p=q.top();q.pop();
ll et=-p.first;
int u=p.second.first;
if(shp[u]) return et;
if(ss!=h[u].first){
if(!kaari_reitillä(u,h[u].first))
return et+h[u].second;
}
for(auto B:v[u]){
if(B.first==p.second.second||B.second.second==I) continue;
q.push({-et-B.second.first,{B.first,u}});
}
}
return -1;
}
void kysmys(){
int R;
cin>>I>>R;
ll d;
bool p=ppako(R);
if(p){
cout<<"escaped\n";
} else{
if(!kaari_reitillä(R,h[R].first)){
cout<<h[R].second<<'\n';
return;
}
if((d=etäisyys(R,h[R].first))==-1){
cout<<"oo\n";
} else {
cout<<d<<'\n';
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>S>>Q>>E;
for(int i=0;i<N-1;++i){
int A,B,W;
cin>>A>>B>>W;
v[A].push_back({B,{W,i+1}});
v[B].push_back({A,{W,i+1}});
tiet.push_back({A,B});
}
haku(1,0,0);
for(int i=0;i<S;++i){
int s; cin>>s;
shp[s]=1;
shops.push_back(s);
}
haku2();
for(int i=0;i<Q;++i){
kysmys();
}
}
Test details
Test 1
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 5 9 7 ...##.... ..#.##..# ..#....## .##...#.. ... |
| correct output |
|---|
| 22 |
| user output |
|---|
| (empty) |
Test 2
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ................................. |
| correct output |
|---|
| 8272 |
| user output |
|---|
| (empty) |
Test 3
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#...#.#..#.....#.........#...... |
| correct output |
|---|
| 5 |
| user output |
|---|
| (empty) |
Test 4
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#...##...#...##....##.#.##..#... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 5
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ..#.#.#..###.#.#.##..########.... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 6
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#.#.###########..#.###.######... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 7
Group: 1, 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ##############################... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 8
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ................................. |
| correct output |
|---|
| 9503 |
| user output |
|---|
| (empty) |
Test 9
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 #..#.##..#....##...#.##.##..#.... |
| correct output |
|---|
| 495 |
| user output |
|---|
| (empty) |
Test 10
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 #.#...######.#####.#.##...#.##... |
| correct output |
|---|
| 51 |
| user output |
|---|
| (empty) |
Test 11
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#.#.###########..#.###.######... |
| correct output |
|---|
| 34 |
| user output |
|---|
| (empty) |
Test 12
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ##############################... |
| correct output |
|---|
| 19 |
| user output |
|---|
| (empty) |
Test 13
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ................................. |
| correct output |
|---|
| 9801 |
| user output |
|---|
| (empty) |
Test 14
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ..............#.................. |
| correct output |
|---|
| 7479 |
| user output |
|---|
| (empty) |
Test 15
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 #.#.........###.#..#.#..####.#... |
| correct output |
|---|
| 5328 |
| user output |
|---|
| (empty) |
Test 16
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#.#.###########..#.###.######... |
| correct output |
|---|
| 127 |
| user output |
|---|
| (empty) |
Test 17
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ##############################... |
| correct output |
|---|
| 19 |
| user output |
|---|
| (empty) |
Test 18
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ................................. |
| correct output |
|---|
| 10000 |
| user output |
|---|
| (empty) |
Test 19
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ..............#.................. |
| correct output |
|---|
| 8047 |
| user output |
|---|
| (empty) |
Test 20
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 #.#...######.#####.#.##...#.##... |
| correct output |
|---|
| 3500 |
| user output |
|---|
| (empty) |
Test 21
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 .#.#.###########..#.###.######... |
| correct output |
|---|
| 1228 |
| user output |
|---|
| (empty) |
Test 22
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 100 100 ##############################... |
| correct output |
|---|
| 43 |
| user output |
|---|
| (empty) |
Test 23
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ................................. |
| correct output |
|---|
| 249493 |
| user output |
|---|
| (empty) |
Test 24
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 #..#.##..#....##...#.##.##..#.... |
| correct output |
|---|
| 222 |
| user output |
|---|
| (empty) |
Test 25
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 .#####....####..###...####.#.#... |
| correct output |
|---|
| 1268 |
| user output |
|---|
| (empty) |
Test 26
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 #.#####.##..#####.####..######... |
| correct output |
|---|
| 805 |
| user output |
|---|
| (empty) |
Test 27
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ##############################... |
| correct output |
|---|
| 349 |
| user output |
|---|
| (empty) |
Test 28
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ................................. |
| correct output |
|---|
| 249999 |
| user output |
|---|
| (empty) |
Test 29
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ..............#.................. |
| correct output |
|---|
| 197917 |
| user output |
|---|
| (empty) |
Test 30
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 #.#.........###.#..#.#..####.#... |
| correct output |
|---|
| 79550 |
| user output |
|---|
| (empty) |
Test 31
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 #.#####.##..#####.####..######... |
| correct output |
|---|
| 1221 |
| user output |
|---|
| (empty) |
Test 32
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ##############################... |
| correct output |
|---|
| 1414 |
| user output |
|---|
| (empty) |
Test 33
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ................................. |
| correct output |
|---|
| 250000 |
| user output |
|---|
| (empty) |
Test 34
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ..............#.................. |
| correct output |
|---|
| 199752 |
| user output |
|---|
| (empty) |
Test 35
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 .#####....####..###...####.#.#... |
| correct output |
|---|
| 87691 |
| user output |
|---|
| (empty) |
Test 36
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 #.#####.##..#####.####..######... |
| correct output |
|---|
| 30998 |
| user output |
|---|
| (empty) |
Test 37
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 500 500 5000 ##############################... |
| correct output |
|---|
| 1440 |
| user output |
|---|
| (empty) |
