Submission #527746

#TimeUsernameProblemLanguageResultExecution timeMemory
527746jalsolValley (BOI19_valley)C++11
23 / 100
95 ms15316 KiB
#include <bits/stdc++.h> using namespace std; #define Task "" struct __Init__ { __Init__() { cin.tie(nullptr)->sync_with_stdio(false); if (fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } } } __init__; using ll = long long; #ifdef LOCAL #define debug(x) cerr << "[" #x " = " << x << "]\n"; #else #define debug(...) #endif // LOCAL #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fi first #define se second #define For(i, l, r) for (int i = (l); i <= (r); ++i) #define Ford(i, r, l) for (int i = (r); i >= (l); --i) #define Rep(i, n) For (i, 0, (n) - 1) #define Repd(i, n) Ford (i, (n) - 1, 0) template<class C> int isz(const C& c) { return c.size(); } template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } constexpr int eps = 1e-9; constexpr int inf = 1e9; constexpr ll linf = 1e18; // ============================================================================= constexpr int maxN = 1e5 + 5; struct Edge { int u, v, c; int other(int x) const { return u ^ v ^ x; } }; int n, ns, nq, root; vector<int> g[maxN]; Edge e[maxN]; int tin[maxN], tout[maxN], timer; void Dfs(int u, int p) { tin[u] = ++timer; for (int i : g[u]) { int v = e[i].other(u); if (v != p) { Dfs(v, u); } } tout[u] = ++timer; } bool isAnc(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; } signed main() { cin >> n >> ns >> nq >> root; assert(n == ns); For (i, 1, n - 1) { int u, v, c; cin >> u >> v >> c; e[i] = {u, v, c}; g[u].push_back(i); g[v].push_back(i); } For (i, 1, ns) { int x; cin >> x; } Dfs(root, -1); Rep (_, nq) { int i, x; cin >> i >> x; int u = e[i].u; int v = e[i].v; if (tin[u] > tin[v]) swap(u, v); if (!isAnc(v, x)) { cout << "escaped\n"; continue; } cout << 0 << '\n'; } } /* escaped => euler tour? */

Compilation message (stderr)

valley.cpp: In constructor '__Init__::__Init__()':
valley.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             freopen(Task".inp", "r", stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
valley.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             freopen(Task".out", "w", stdout); }
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...