제출 #338445

#제출 시각아이디문제언어결과실행 시간메모리
338445alishahali1382Bitaro’s Party (JOI18_bitaro)C++14
100 / 100
830 ms261612 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O2,unroll-loops") //#pragma GCC optimize("no-stack-protector,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<pii, int> piii; typedef pair<ll, ll> pll; #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl; #define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl; #define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;} #define all(x) x.begin(), x.end() #define pb push_back #define kill(x) return cout<<x<<'\n', 0; const int inf=1000000010; const ll INF=10000000000000010LL; const int mod=1000000007; const int MAXN=100010, SQ=320; int n, m, q, u, v, x, y, t, a, b, shit; int dp[MAXN], mark[MAXN], sz[MAXN]; pii A[MAXN][SQ], B[2*SQ]; vector<int> G[MAXN]; int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin>>n>>m>>q; while (m--){ cin>>u>>v; G[v].pb(u); } for (int v=1; v<=n; v++){ A[v][sz[v]++]={-1, v}; for (int u:G[v]){ shit++; int t=sz[v]+sz[u]; merge(A[v], A[v]+sz[v], A[u], A[u]+sz[u], B, [](pii i, pii j){ return i.first>j.first; }); sz[v]=0; for (int i=0; i<t && sz[v]<SQ; i++) if (mark[B[i].second]!=shit){ mark[B[i].second]=shit; A[v][sz[v]++]=B[i]; } } for (int i=0; i<sz[v]; i++) A[v][i].first++; } memset(mark, 0, sizeof(mark)); for (shit=1; shit<=q; shit++){ cin>>v>>t; while (t--) cin>>x, mark[x]=shit; bool ok=0; for (int i=0; i<sz[v]; i++) if (mark[A[v][i].second]!=shit){ cout<<A[v][i].first<<"\n"; ok=1; break ; } if (ok) continue ; for (int i=1; i<=v; i++){ if (mark[i]==shit) dp[i]=-inf; else dp[i]=0; for (int u:G[i]) dp[i]=max(dp[i], dp[u]+1); } if (dp[v]<0) dp[v]=-1; cout<<dp[v]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...