Submission #731093

#TimeUsernameProblemLanguageResultExecution timeMemory
731093vjudge1Bitaro’s Party (JOI18_bitaro)C++17
0 / 100
2076 ms102340 KiB
#include <bits/stdc++.h> #define sts stable_sort #define B begin() #define rB rbegin() #define E end() #define rE rend() #define F first #define S second #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define eb emplace_back #define ll long long #define ui unsigned int #define ull unsigned long long using namespace std; const int MAXN = 1e4 + 4; const int MOD = 1e9 + 7; const ll INF = 9223372036854775807LL; const ll inf = 2147483647; vector<int> add[MAXN]; bool inv[MAXN][MAXN]; int dist[MAXN][MAXN]; void f(int nod){ queue<pair<int, int> > q; q.push({nod, 0}); while(!q.empty()){ pair<int, int> x = q.front(); q.pop(); if(x.F > nod)continue; dist[nod][x.F] = max(dist[nod][x.F], x.S); for(auto &c : add[x.F]){ q.push({c, x.S + 1}); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, Q; cin >> n >> m >> Q; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; add[b].pb(a); } bool comp[n]; while(Q--){ int a, b; cin >> a >> b; bool c = 0; for(int i = 0; i < b; i++){ int x; cin >> x; inv[a][x] = 1; } int maxi = 0; if(!comp[a]){ f(a); comp[a] = 1; } for(int i = 1; i <= a; i++){ if(inv[a][i]){ inv[a][i] = 0; continue; } c = 1; maxi = max(maxi, dist[a][i]); } if(!c)cout << "-1\n"; else cout << maxi << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...