This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//to avoid hacking but when offline not necessary
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
int operator()(int x) const { return x ^ RANDOM; }
};
#define ld long double
#define ll long long
//#define int ll
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(),cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define FOR(i, j) for(int i=0;i<j;i++)
#define RFOR(i, j) for (int i=j;i>=0;i--)
#define GO cin.tie(NULL);
#define FAST ios_base::sync_with_stdio(false);
#define prec(x) cout << fixed << setprecision(x)
#define sz(x) (int)x.size()
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<pii> VPII;
typedef vector<VI> VVI;
typedef priority_queue<int> max_heap;
typedef priority_queue<pii> max_heapii;
typedef priority_queue<int,VI,greater<int>> min_heap;
typedef priority_queue<pii,VPII,greater<pii>> min_heapii;
const long double PI = 3.14159265359;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b){return uniform_int_distribution<ll>(a, b)(rng);}
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cout << vars << " = ";
string delim = "";
(..., (cout << delim << values, delim = ", "));
cout<<endl;
}
void print(vector<int>v){
cout<<"[";
FOR(i,v.size()){
cout<<v[i];
if(i+1!=v.size())cout<<", ";
}
cout<<"]"<<endl;
}
void print(pii p){
cout<<"{"<<p.first<<", "<<p.second<<"}"<<endl;
}
const int maxn=1e5+10;
const int magic=100;
VI grafo[maxn];
vector<pair<gp_hash_table<int,null_type,chash>,int>> light[maxn];
vector<pair<gp_hash_table<int,null_type,chash>,int>> heavy[maxn];
int ans[maxn];
VPII caches[maxn];
int n,m,q;
void solvelight(int u,pair<gp_hash_table<int,null_type,chash>,int>& cara){
for(auto k:caches[u])if (cara.first.find(k.second)==cara.first.end()){
ans[cara.second]=k.first;
return;
}
ans[cara.second]=-1;
}
void solvelight(int u){
for(auto k:light[u])solvelight(u,k);
}
void solvelight(){
FOR(i,n){
if (!light[i].empty())solvelight(i);
}
}
void merja(int u){
VI inds(grafo[u].size(),0);
gp_hash_table<int,null_type,chash> botados;
priority_queue<pair<pii,int>> caras;
int cont=0;
//deb(u);
for(auto k:grafo[u]){
//print(caches[k][0]);
//deb(k,cont);
caras.push({caches[k][0],cont});
cont++;
}
//deb(u);
while((!caras.empty()) && (caches[u].size()<magic)){
//deb(sz(caras));
auto o=caras.top();
//print(o.first);
//deb(o.second);
caras.pop();
if (botados.find(o.FS)==botados.end()){
botados.insert(o.FS);
caches[u].push_back({o.FF+1,o.FS});
}
if((inds[o.second]+1)<sz(caches[grafo[u][o.second]])){
caras.push({caches[grafo[u][o.second]][inds[o.second]+1],o.second});
inds[o.second]++;
}
}
//cout<<endl;
}
void precalc(){
FOR(i,n){
merja(i);
if (caches[i].size()<magic)caches[i].push_back({0,i});
}
}
int dist[maxn];
void solveheavy(int u){
FOR(i,u+1)dist[i]=-1;
dist[u]=0;
for(int i=u;i>=0;i--){
if(dist[i]!=-1) for(auto k:grafo[i])dist[k]=max(dist[k],dist[i]+1);
}
}
void solveheavy(int u,const pair<gp_hash_table<int,null_type,chash>,int> &cara){
int maior=-1;
for(int i=u;i>=0;i--){
if(cara.first.find(i)==cara.first.end())maior=max(maior,dist[i]);
}
ans[cara.second]=maior;
}
void solveheavy(){
FOR(i,n){
if(!heavy[i].empty()){
solveheavy(i);
for(auto& k:heavy[i]){
solveheavy(i,k);
}
}
}
}
signed main(){
GO FAST
cin>>n>>m>>q;
FOR(i,m){
int a,b;cin>>a>>b;a--;b--;
grafo[b].PB(a);
}
precalc();
FOR(i,q){
int f,k;
cin>>f>>k;
f--;
gp_hash_table<int,null_type,chash> sett;
FOR(j,k){
int a;cin>>a;a--;
sett.insert(a);
}
if (k>=(magic-2)){
heavy[f].PB(MP(sett,i));
}
else{
light[f].PB(MP(sett,i));
}
}
solvelight();
solveheavy();
FOR(i,q){
cout<<ans[i]<<'\n';
}
}
Compilation message (stderr)
bitaro.cpp: In function 'void print(std::vector<int>)':
bitaro.cpp:26:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | #define FOR(i, j) for(int i=0;i<j;i++)
......
57 | FOR(i,v.size()){
| ~~~~~~~~~~
bitaro.cpp:57:2: note: in expansion of macro 'FOR'
57 | FOR(i,v.size()){
| ^~~
bitaro.cpp:59:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(i+1!=v.size())cout<<", ";
| ~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |