This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int n, s, q, e ;
vector<pair<int,int>> edge [200005];
long long tin[200005], tout [200005];
vector<int> v;
void dfs ( int nod,int p )
{
v.push_back(nod);
if (tin[nod] == 0 )
{
tin [nod] = v.size() ;
}
for ( auto u : edge[nod] )
{
if ( u.first != p)
{
dfs (u.first, nod );
v.push_back(nod);
}
}
tout[nod] = v.size();
}
vector<pair<int,int>> qr;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s >> q >> e;
for ( int i =1; i < n ; i ++ )
{
int a, b,c;
cin >> a >> b>>c;
edge[a].push_back({b,c});
edge[b].push_back({a,c});
qr.push_back({a,b});
}
dfs(e,0);
for( int i = 1; i <= s; i ++ )
{
int val;
cin >> val ;
}
for ( int i = 1; i <= q; i ++ )
{
int l, r;
cin >> l >> r ;
l -- ;
int a = qr[l].first;
int b = qr[l].second;
int tg ;
if ( tin[a] < tin[b] && tout[a] > tout[b])
tg =b ;
else
tg = a;
if ( tin[tg] <= tin[r] && tout[tg] >= tout[r])
{
cout << 0 << '\n';
}
else
cout << "escaped" << '\n';
}
return 0;
}
# | 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... |