Submission #442145

#TimeUsernameProblemLanguageResultExecution timeMemory
442145PixelCatBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1324 ms274440 KiB
/* code by the cute PixelCat owo */ /* as cute as nyachoneko chan! */ //#pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #define int ll //__int128 #define double long double using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<int,int>; #define For(i,a,b) for(int i=a;i<=b;i++) #define Fors(i,a,b,s) for(int i=a;i<=b;i+=s) #define Forr(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define L(id) (id*2+1) #define R(id) (id*2+2) #define LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (int)(1000000007) #define INF (int)(1e17) #define EPS (1e-6) #ifdef NYAOWO #define debug(...) do{\ cerr << __LINE__ <<\ " : ("#__VA_ARGS__ << ") = ";\ _OUT(__VA_ARGS__);\ cerr << flush;\ }while(0) template<typename T> void _OUT(T _X) { cerr << _X << "\n"; } template<typename T,typename...I> void _OUT(T _X,I ...tail) { cerr << _X << ", "; _OUT(tail...); } inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; } #else #define debug(...) inline void USACO(const string &s){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #endif inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int gcd(int a,int b) { return __gcd(a,b); } inline int lcm(int a,int b) { return a/gcd(a,b)*b; } int fpow(int b,int p,const int &mod){ int ans=1; while(p){ if(p&1) ans=ans*b%mod; p/=2; b=b*b%mod; } return ans; } int fpow(int b,int p) { return fpow(b,p,MOD); } template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; } template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; } const int SQ=100; vector<int> adj[100010]; int gg[100010]; int dp[100010]; int meow(int n){ For(i,1,n){ if(gg[i]) dp[i]=-INF; else dp[i]=0; for(auto &j:adj[i]) chmax(dp[i],dp[j]+1); } if(dp[n]<0) return -1; return dp[n]; } vector<pii> owo[100010]; //id,distance int dist[100010]; void oao(int n){ For(i,1,n){ vector<int> v; for(auto &j:adj[i]) for(auto &k:owo[j]){ if(dist[k.F]==0) v.eb(k.F); chmax(dist[k.F],k.S+1); } for(auto &j:v){ owo[i].eb(j,dist[j]); dist[j]=0; } owo[i].eb(i,0); sort(all(owo[i]),[](pii a,pii b){ return a.S>b.S; }); if(sz(owo[i])>SQ) owo[i].erase(owo[i].begin()+SQ,owo[i].end()); } } int32_t main(){ NYA(); //nyaacho >/////< int n,m; cin>>n>>m; int q; cin>>q; while(m--){ int a,b; cin>>a>>b; adj[b].eb(a); } oao(n); while(q--){ int t; cin>>t; int ni; cin>>ni; vector<int> v(ni); for(auto &i:v){ cin>>i; gg[i]=true; } if(ni>=SQ) cout<<meow(t)<<"\n"; else{ for(auto &i:owo[t]) if(!gg[i.F]){ cout<<i.S<<"\n"; goto NameSoHard; } cout<<"-1\n"; } NameSoHard:; for(auto &i:v) gg[i]=false; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...