/*
.;;;;:
:::::::;
;::::::;
:;;;;.
;:::;
;:::::;; ;;;
::::::::::;; ;:::
;:::::::::::;;: .;;:::
.;::::::::::::::;;. .:.:::: ;;;:::;;;
:;:::::::::::::::::;;. :. .::::....: :;;::::::::;
;::::::::::....:::::::;;;;;;;;;;: .:... ....:..: .;;::::::::::::;
:;::::::::........::::::::::::::. :. .. ... . .....;;;:::::::::::::::;
;::::::::..........::::::::::::: .... ..... .....:::::::::::::::::;:
.;:::::::...........:::::::::::: :.. ... ...........:::::::::::::::;.
......................::::::::::: .. .... ..............:::::::::::;
..........:::.......:::::::::::::. . .. .... ............:::::::::;
..........::::::::::::::::.......: .:.... ... ........ .: ::::::;;
........:::::::::::::...........:. ::. .... .... .... .: .::::;:
.......:::::::::::::..............::. .::.. .. .... .:..:::;:
...::::::::::::::::..:::....::....::::. :.... .... .... : ::.
;::::::::::::::::::..::.....:::...::::::::. .:. ... ..... .. .
:;::::::::;; .;:::::............::::::::::: :.... ... .. :.:
;:::::::;. ;;:::.......:::::;;;;..;;;::. :.... .... ...:
;:::::;: .;;::::::;;;;. ;;:... .. .. .:. .
;:::::: :;;: .;:: ....... .:. :
;::::; ;. ;;:: :::.. .:;:
;;::;: :;;;;;; .;::::::::::::;
;::;: .;;;;;;; :;::::::::::::
.;:;: .::;;;;; .;::::::::::;.
.;;;.....;;;;;; ... .;:::::::::;.
;;:.... .:. ;;;;;; :;::::::::;.
:;:......... ..... ;:::::::;:
............. .. ...... :;:::::;:
................... .;;;. .:;. ;;:::;;:
.. ....... ..:;;:;; ;: :;::;;:
;.:::.. ..........:;;;;; .;...:.;;;;;. .
:;:;.................;.;:; ;::::::::: ;;;:::
.;....:........;; ;;:::; .:::::;;:::;.:::. .;:::::::
.:...:; ;..:.:.:::.:;;;:::. :;:: : ..:.:. .;:::::
::.........;;+:....:; .:..:: .::..; ;::;:;;:
;:...........::;;;;;: .:: .; ::..:. :. ;:::;. :.
::::::...;. :::: ..;;;. ;. ;;:::;.
.. ::.;:.;: .::;;; ;;;:::;;.
::.; :;;;;:::........; ;:::;:
.;...::::........;:.....:; ;:
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define rev(i,a,b) for(int i=a; i>=b; --i)
#define getbit(mask,i) (1ll&(mask>>i))
#define all(v) (v).begin(),(v).end()
#define isz(v) (int)(v).size()
#define pii pair<int,int>
using namespace std;
const ll inf = 998244353;
const ll pvhmod = 1e9 +22071997;
const ll moreinf = 1e18 + 7;
const ll base = 256;
const ll mod = (1ll<<31) - 1;
const int sz = 100;
inline ll CELL(ll a, ll b){return a/b + (a%b>0);}
inline ll FLOOR(ll a, ll b){return a/b - (a%b<0);}
const int maxN = 1e5+7;
int n,m,q;
vector<int> g[maxN];
vector<pii> longest_path[maxN];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen("code.inp","r")){
freopen("code.inp","r",stdin);
freopen("code.out","w",stdout);
}
cin >> n >> m >> q;
rep(i,1,m){
int u,v; cin >> u >> v;
g[v].push_back(u);
}
vector<int> found(n+2,0),cur_longest(n+2,0), processed;
rep(u,1,n){
longest_path[u].push_back({0,u});
for(int v:g[u]){
for(pii p:longest_path[v]){
int idx = p.second, len = p.first;
if(!found[idx]){
processed.push_back(idx);
found[idx] = 1;
cur_longest[idx] = len + 1;
}else{
cur_longest[idx] = max(cur_longest[idx], len + 1);
}
}
}
for(int x:processed) longest_path[u].push_back({cur_longest[x],x});
sort(longest_path[u].rbegin(), longest_path[u].rend());
while(isz(longest_path[u])>sz + 3) longest_path[u].pop_back();
for(int x:processed) cur_longest[x] = found[x] = 0;
//
processed.clear();
}
// rep(u,1,n){
// cout << u << endl;
// for(pii p:longest_path[u]) cout << p.first << " " << p.second << endl;
// }
while(q--){
int t,y; cin >> t >> y;
int ans = -1;
vector<int> blocked(n+2,0);
rep(i,1,y){
int x; cin >> x;
blocked[x] = 1;
}
if(y>sz){
vector<int> dp(n+2,-1);
dp[t] = 0;
rev(u,t,1){
if(dp[u]==-1) continue;
for(int v:g[u]) dp[v] = max(dp[v],dp[u] + 1);
if(!blocked[u]) ans = max(ans, dp[u]);
}
}else{
for(pii p:longest_path[t]){
if(!blocked[p.second]) {
ans = p.first;
break;
};
}
}
cout << ans << endl;
}
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int main()':
bitaro.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen("code.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen("code.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |