Submission #926353

#TimeUsernameProblemLanguageResultExecution timeMemory
926353OAleksaPassport (JOI23_passport)C++14
0 / 100
530 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 2e5 + 69; int n, l[N], r[N], q, p[N]; vector<int> g[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; for (int i = 1;i <= n;i++) { cin >> l[i] >> r[i]; for (int j = l[i];j <= r[i];j++) { g[i].push_back(j); } } cin >> q; for (int i = 1;i <= q;i++) { int x; cin >> x; queue<int> q; q.push(x); vector<int> dis(n + 1, 1e9); dis[x] = 0; while (!q.empty()) { auto v = q.front(); q.pop(); for (auto u : g[v]) { if (dis[u] <= dis[v] + 1) continue; dis[u] = dis[v] + 1; q.push(u); } } int ans = -1; for (int i = 1;i <= n;i++) ans = max(ans, dis[i]); if (ans == 1e9) ans = -1; cout << ans << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...