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 <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << endl;
#define kill(x) {cout << x << '\n'; continue;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e14, mod = 1e9 + 7, delta = 1e8, SQ = 800; //998244353
using namespace std;
const ll N = 1e5 + 10, LG = 20;
#define piii array<int, 3>
int cnt, st[N], ft[N];
vector<piii> adj[N];
vector<int> maghaze, t;
pll par[N], d[N], dd[N], edges[N];
void dfs (int v, int p, int e) {
t.pb(v);
st[v] = cnt++;
par[v] = pii(p, e);
for (auto u: adj[v])
if (u[0] - p) dfs(u[0], v, u[2]);
ft[v] = cnt;
}
bool cmp (piii a, piii b){
return a[1] < b[1];
}
int32_t main() {
fast_io;
int n, s, q, e;
cin >> n >> s >> q >> e;
for (int i = 1; i < n; i++) {
int u, v, w;
cin >> u >> v >> w;
adj[u].pb({v, w, i});
adj[v].pb({u, w, i});
edges[i] = pii(u, v);
}
for (int i = 1; i <= s; i++) {
int v;
cin >> v;
maghaze.pb(v);
}
dfs(1, -1, -1);
for (int j = 1; j <= q; j++) {
int ii, r;
cin >> ii >> r;
int u = edges[ii].F, v = edges[ii].S;
if (v == par[u].F) swap(u, v);
bool b = (st[e] >= st[v] && st[e] < ft[v]), bb = (st[r] >= st[v] && st[r] < ft[v]);
if (b && bb) cout << "escaped\n";
else if (b || bb) 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... |