Submission #374257

#TimeUsernameProblemLanguageResultExecution timeMemory
374257i_am_noobBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1370 ms172268 KiB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,avx512f") #include<bits/stdc++.h> #pragma GCC optimize("unroll-loops") using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back #define inf 1010000000 //#define inf 4000000000000000000 #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {static int cnt=0;cerr << x << endl;cnt++;if(cnt>1000) exit(0);} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 826 #endif inline char readchar(){ const int maxn=1000000; static char buf[maxn],*p=buf,*q=buf; if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF; else return *p++; } inline int readint(){ int c=readchar(),x=0,neg=0; while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar(); if(c=='-') neg=1,c=readchar(); while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar(); return neg?-x:x; } const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; const int maxn=100005; //i_am_noob const int K=205; int n,m,pos[maxn][K],val[maxn][K],maxx[maxn],q,x,k; vector<int> adj[maxn],vec,vec1; bool vis[maxn]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); #ifdef i_am_noob freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); freopen("output2.txt","w",stderr); #endif n=readint(),m=readint(),q=readint(); rep(m){ int u,v; u=readint(),v=readint(); adj[v-1].pb(u-1); } rep(n) maxx[i]=-inf; rep(n){ rep1(j,K) val[i][j]=-inf; vec.clear(),vec1.clear(); for(auto v: adj[i]) rep1(j,K) maxx[pos[v][j]]=max(maxx[pos[v][j]],val[v][j]+1),vec.pb(pos[v][j]); maxx[i]=max(maxx[i],0),vec.pb(i); for(auto j: vec) if(maxx[j]>=0&&!vis[j]) vec1.pb(j),vis[j]=1; sort(all(vec1),[](int p, int q){return maxx[p]>maxx[q];}); rep1(j,min(sz(vec1),K)) val[i][j]=maxx[vec1[j]],pos[i][j]=vec1[j]; for(auto j: vec1) vis[j]=0,maxx[j]=-inf; } memset(vis,0,sizeof vis); while(q--){ x=readint(),k=readint(); x--; vec.clear(); vec.resize(k); rep(k) vec[i]=readint(); rep(k) vec[i]--,vis[vec[i]]=1; if(k<K){ rep(K) if(val[x][i]<0||!vis[pos[x][i]]){ cout << (val[x][i]<0?-1:val[x][i]) << "\n"; break; } rep(k) vis[vec[i]]=0; continue; } rep(x+1) maxx[i]=-inf; rep(x+1){ for(auto v: adj[i]) maxx[i]=max(maxx[i],maxx[v]+1); if(!vis[i]) maxx[i]=max(maxx[i],0); } cout << (maxx[x]<0?-1:maxx[x]) << "\n"; rep(k) vis[vec[i]]=0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...