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>
#define endl '\n'
#define int long long
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
vector<int>adj[200001],radj[200001];
int no[200001],dis[200001];
signed main(){
boost;
int n,m,q; cin >> n >> m >> q;
for(int i = 0; i < m; i++){
int a,b; cin >> a >> b;
adj[a].push_back(b);
radj[b].push_back(a);
}
int t,y, ans = -1; cin >> t >> y;
for(int i = 0; i < y; i++){
int x; cin >> x;
no[x] = 1;
}
priority_queue<pair<int,int>>x;
x.push({0,t});
while(x.size()){
auto s = x.top();
x.pop();
if(dis[s.second] > s.first) continue;
if(!no[s.second]) ans = max(ans,dis[s.second]);
for(auto e:radj[s.second]){
if(dis[s.second] + 1 > dis[e]){
dis[e] = dis[s.second] + 1;
x.push({dis[e],e});
}
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |