Submission #567180

#TimeUsernameProblemLanguageResultExecution timeMemory
567180AbdullahMWBitaro’s Party (JOI18_bitaro)C++17
0 / 100
18 ms4436 KiB
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() #define ll long long #define db double #define pb push_back #define pf push_front #define newl "\n" #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define f first #define s second #define MOD 1000000007 using namespace std; #pragma GCC diagnostic ignored "-Wunused-result" void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(15); if (name.size()) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } vector <ll> gr[100005]; unordered_map <ll, unordered_map <ll, ll>> path; void bfs(ll beg) { queue <pair <ll, ll>> q; unordered_map <ll, bool> vis; q.push({0, beg}); while (q.size()) { ll x = q.front().s, len = q.front().f; q.pop(); if (!vis[x]) { vis[x] = true; for (auto v : gr[x]) { q.push({len + 1, v}); path[beg][v] = max(path[beg][v], len + 1); } } } } int main() { fast //setIO(""); //freopen("filename.in", "r", stdin); //freopen("filename.out", "w", stdout); ll n, m, q; cin >> n >> m >> q; for (ll i = 1; i <= m; i++) { ll x, y; cin >> x >> y; gr[x].pb(y); } for (ll i = 1; i <= n; i++) { bfs(i); } while (q--) { ll t, f; cin >> t >> f; unordered_map <ll, bool> busy; for (ll i = 1; i <= f; i++) { ll fr; cin >> fr; busy[fr] = true; } ll mx = -1; if (!busy[t]) mx = 0; for (ll i = 1; i <= n; i++) { if (!busy[i] && i != t && path[i][t] > 0) mx = max(mx, path[i][t]); } cout << mx << newl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...