제출 #1349161

#제출 시각아이디문제언어결과실행 시간메모리
1349161sash01Bitaro’s Party (JOI18_bitaro)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
#define control cout<<"e ne"<<endl;
#define endl '\n'
using namespace std;
int n,m,q,t,y,u[131072],used[131072],x,mx;
vector <int> v[131072];
void speed()
{
 ios_base::sync_with_stdio(false);
 cin.tie(0);
}
void bfs()
{
    queue <int> q;
    q.push(t);
    while(!q.empty())
    {
        int w=q.front();
        q.pop();
        for(auto nb:v[w])
        {
            if(!used[nb])
            {
                used[nb]=used[w]+1;
                q.push(nb);
            }
        }
    }
}
void solve()
{
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[y].push_back(x);
    }
    cin>>t>>y;
    for(int i=1;i<=y;i++)
    {
        cin>>x;
        u[x]=1;
    }
    used[t]=1;
    bfs();
    mx=-1;
    for(int i=1;i<=n;i++)
    {
        if(!u[i])mx=max(mx,used[i]-1);
    }
    cout<<mx<<endl;
}
signed main()
{
    /*
    #ifdef ONLINE_JUDGE
    freopen("txt.in","r",stdin)
    freopen("txt.out","w",stdout)
    #endif
    */
    speed();
    //int t; cin>>t; while(t--)
    solve();
    return 0;
}
/*
5 6 3
1 2
2 4
3 4
1 3
3 5
4 5
4 1 1
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...