Submission #559589

#TimeUsernameProblemLanguageResultExecution timeMemory
559589KaipaloBitaro’s Party (JOI18_bitaro)C++14
7 / 100
1759 ms524288 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string.h> using namespace std; const int sqrt = 300; int n, m, q; vector <int> parent[100005]; struct st { int idx, d; bool operator < (const st &other) const { return d > other.d; } }; vector <int> canGo; vector <st> dist[100005]; st visited[100005]; int busy[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> q; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; parent[v].push_back(u); } for (int i = 1; i <= n; i++) { canGo.clear(); canGo.push_back(i); visited[i] = {i, 0}; for (auto p : parent[i]) { for (auto go : dist[p]) { if (visited[go.idx].idx != i) { visited[go.idx] = {i, 1 + go.d}; canGo.push_back(go.idx); } else { if (visited[go.idx].d < 1 + go.d) { visited[go.idx].d = 1 + go.d; } } } } for (auto go : canGo) { dist[i].push_back({go, visited[go].d}); } sort(dist[i].begin(), dist[i].end()); } for (int i = 1; i <= q; i++) { int t, y; cin >> t >> y; for (int j = 0; j < y; j++) { int x; cin >> x; busy[x] = i; } bool found = false; for (auto e : dist[t]) { if (busy[e.idx] != i) { cout << e.d << '\n'; found = true; break; } } if (!found) cout << -1 << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...