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>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
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 all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const ld eps=1e-7;
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, ans;
vector<pii> good[MAXN];
int dp[MAXN];
vector<int> G[MAXN];
void merg(int a, int b){
vector<pii> tmp;
for (int i=0, j=0; i+j<SQ && i+j<good[a].size()+good[b].size()-1;){
pii pp={good[b][j].first+1, good[b][j].second};
if (good[a][i]>pp) tmp.pb(good[a][i++]);
else tmp.pb(pp), j++;
}
good[a].clear();
for (pii p:tmp) good[a].pb(p);
}
void bigquery(){
while (y--){
cin>>x;
dp[x]=-inf;
}
for (int i=1; i<=v; i++) for (int j:G[i]) dp[i]=max(dp[i], dp[j]+1);
if (dp[v]<0) dp[v]=-1;
cout<<dp[v]<<'\n';
memset(dp, 0, sizeof(dp));
}
int smallquery(){
set<int> st;
while (y--){
cin>>x;
st.insert(x);
}
for (pii p:good[v]){
if (st.count(p.second)) continue ;
kill(p.first);
}
cout<<"-1\n";
}
void query(){
cin>>v>>y;
if (y>=SQ) bigquery();
else smallquery();
}
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 i=1; i<=n; i++){
good[i].pb({0, i});
good[i].pb({-inf, 0});
for (int j:G[i]) merg(i, j);
}
for (int i=1; i<=n; i++) good[i].pop_back();
while (q--) query();
return 0;
}
/*
.---. .---. ...-' |`. ..-'''-. / .--. \ .-''-.
| |.--. . . | |.--. | | |\.-'''\ \ ' ' ' ' .' .-. )
| ||__| .'| .'| | ||__| .... | | | | \ \ / / / .' / /
| |.--. < | < | | |.--. -| | | __/ / `.`'--.' (_/ / /
__ | || | | | __ | | __ | || | | | | |_ '. / `'-. `. / /
.:--.'. | || | _ | | .'''-. .:--.'. | | .'''-. .:--.'. | || | ...' `--' `. \ ' / `. \ / /
/ | \ | | || | .' | | |/.'''. \ / | \ | | |/.'''. \ / | \ | | || | | |`. \ '. / / \ ' . '
`" __ | | | || | . | /| / | | `" __ | | | / | | `" __ | | | || | ` --------\ | , || | | | / / _.-')
.'.''| | | ||__| .'.'| |//| | | | .'.''| | | | | | .'.''| | | ||__| `---------' | || | | |.' ' _.'.-''
/ / | |_'---' .'.'.-' / | | | | / / | |_| | | | / / | |_'---' / ,' \ \ / // /.-'_.'
\ \._,\ '/ .' \_.' | '. | '.\ \._,\ '/| '. | '.\ \._,\ '/ -....--' / `.'-...-'.'/ _.'
`--' `" '---' '---'`--' `" '---' '---'`--' `" `.. __..-' `-...-'( _.-'
*/
Compilation message (stderr)
bitaro.cpp: In function 'void merg(int, int)':
bitaro.cpp:30:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0, j=0; i+j<SQ && i+j<good[a].size()+good[b].size()-1;){
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp: In function 'int smallquery()':
bitaro.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |