This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> g[N],rg[N],v;
ll n,m,Q,x,y,sz,target,S,val[N];
ll ban[N],dd[N];
ll DFS(ll u){
if (val[u] != -1) return val[u];
if (u == target) return 0;
ll ans = -inf;
for (auto i : g[u]) ans = max(ans,1 + DFS(i));
return val[u] = ans;
}
deque<LL> dq[N]; /// fs = val sc = id
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>m>>Q; S = sqrt(n);
while(m--){
cin>>x>>y;
g[x].push_back(y); rg[y].push_back(x);
}
for (ll i = 1;i <= n;i++){
bool flag = 0; //cout<<rg[i].size(); //return 0;
for (ll j = 0;j < rg[i].size();j++) dd[j] = 0; //return 0;
while(dq[i].size() < S){
LL mx = {-1,i};
if (flag) mx = {-inf,0};
for (ll j = 0;j < rg[i].size();j++){
ll cur = dd[j],now = rg[i][j];
if (cur < dq[now].size()) mx = max(mx,dq[now][cur]);
}
if (mx.sc == i) flag = 1;
dq[i].push_back({mx.fs + 1,mx.sc});
for (ll j = 0;j < rg[i].size();j++){
ll cur = dd[j],now = rg[i][j];
if (cur >= dq[now].size()) continue;
if (mx == dq[now][cur]) dd[j]++;
}
}
//return 0;
}
//return 0;
/*
for (ll i = 1;i <= n;i++){
cout<<i<<":\n";
for (auto j : dq[i]) cout<<j.fs<<" "<<j.sc<<"\n"; cout<<"\n";
}
*/
//return 0;
while(Q--){
cin>>target>>sz; v.clear();
for (ll i = 1;i <= sz;i++) cin>>x,v.push_back(x),ban[x] = 1;
if (sz >= S){
memset(val,-1,sizeof(val));
ll ans = -1;
for (ll i = 1;i <= n;i++){
if (ban[i]) continue;
ans = max(ans,DFS(i)); //cout<<i<<" "<<DFS(i)<<"\n";
}
cout<<ans<<"\n";
}
else{
LL ans = {-1,0};
for (auto i : dq[target]) if (!ban[i.sc]) ans = max(ans,i);
cout<<ans.fs<<"\n";
}
for (auto i : v) ban[i] = 0;
}
}
Compilation message (stderr)
bitaro.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
bitaro.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
bitaro.cpp: In function 'int main()':
bitaro.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (ll j = 0;j < rg[i].size();j++) dd[j] = 0; //return 0;
| ~~^~~~~~~~~~~~~~
bitaro.cpp:43:28: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | while(dq[i].size() < S){
| ~~~~~~~~~~~~~^~~
bitaro.cpp:46:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (ll j = 0;j < rg[i].size();j++){
| ~~^~~~~~~~~~~~~~
bitaro.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if (cur < dq[now].size()) mx = max(mx,dq[now][cur]);
| ~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:52:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (ll j = 0;j < rg[i].size();j++){
| ~~^~~~~~~~~~~~~~
bitaro.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if (cur >= dq[now].size()) continue;
| ~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |