제출 #1108039

#제출 시각아이디문제언어결과실행 시간메모리
1108039TrinhKhanhDungBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1580 ms122620 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(1e9 + 7) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 1e5 + 10, S = 80; int N, M, Q; vector<int> adj[MAX]; vector<pair<int, int>> dp[MAX]; int maxVal[MAX], f[MAX]; bool isDel[MAX]; int calc(int u){ if(f[u] != -1) return f[u]; f[u] = isDel[u] ? -INF : 0; for(int v: adj[u]){ maximize(f[u], calc(v) + 1); } return f[u]; } void solve(){ cin >> N >> M >> Q; for(int i = 1; i <= M; i++){ int u, v; cin >> u >> v; if(u < v) swap(u, v); adj[u].push_back(v); } for(int i = 1; i <= N; i++){ vector<int> lst; lst.push_back(i); maxVal[i] = 0; for(int j: adj[i]){ for(auto x: dp[j]){ maximize(maxVal[x.se], x.fi + 1); lst.push_back(x.se); } } cps(lst); for(int x: lst){ dp[i].push_back({maxVal[x], x}); maxVal[x] = 0; } sort(ALL(dp[i]), greater<pair<int, int>>()); while(sz(dp[i]) > S) dp[i].pop_back(); } while(Q--){ int u, k; cin >> u >> k; vector<int> lst; for(int i = 1; i <= k; i++){ int x; cin >> x; lst.push_back(x); isDel[x] = true; } if(sz(lst) >= S){ memset(f, -1, (N + 3) * sizeof (int)); int ans = calc(u); if(ans < 0) ans = -1; cout << ans << '\n'; } else{ int ans = -1; for(auto x: dp[u]){ if(!isDel[x.se]){ maximize(ans, x.fi); } } cout << ans << '\n'; } for(int x: lst) isDel[x] = false; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("maze.inp","r",stdin); // freopen("maze.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...