137012025-01-08 12:55:16Vkrisztian01Fertőzési sorozat (50 pont)cpp17Wrong answer 31/5017ms2480 KiB
#include <iostream>
#include<bits/stdc++.h>

using namespace std;
const int inf = 1e5 ;

int main()
{
    int n , m , k ;
    cin >> n >> m >> k ;

    vector<int> v(k) ;
    for(int i = 0 ; i < k ; i++)
        cin >> v[i] ;

    vector<vector<int> > adj(n + 1) ;
    for(int i = 1 ; i <= m ; i++)
    {
        int u , v ;
        cin >> u >> v ;

        adj[u].push_back(v) ;
        adj[v].push_back(u) ;
    }

    vector<vector<int> > d(n + 1 , vector<int>(n + 1 , inf)) ;
    vector<vector<int> > cnt(n + 1 , vector<int>(n + 1 , 0)) ;
    for(int i = 1 ; i <= n ; i ++)
    {
        d[i][i] = 0 ;
        cnt[i][0] = 1 ;
    }


    for(int i = 1 ; i <= n ; i++)
    {
        queue<int> q ;
        q.push(i) ;
        while(!q.empty())
        {
            int v = q.front() ;
            q.pop() ;

            for(int to : adj[v])
            {
                if(d[i][to] != inf) continue ;
                d[i][to] = d[i][v] + 1 ;
                cnt[i][d[i][v] + 1 ]++ ;
                q.push(to) ;
            }
        }
    }

    vector<int> ans ;
    for(int i = 1 ; i <= n ; i++)
    {

        int d0 = d[i][v[0] ] ;
        bool good = true ;
        for(int j = 1 ; j < k ; j++)
        {
            int d1 = d[i][v[j - 1] ] ;
            int d2 = d[i][v[j] ] ;

            cnt[i][d1]-- ;

            if(d2 < d1 || (d1 != d0 && cnt[i][d1] > 0) || (d1 + 1 < d2))
                good = false ;
        }

        if(good)
            ans.push_back(i) ;
    }

    cout << ans.size() << "\n" ;
    for(int v : ans)
        cout << v << " " ;


    return 0 ;
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Accepted0/04ms820 KiB
4Accepted2/21ms316 KiB
5Accepted2/22ms316 KiB
6Accepted2/24ms1012 KiB
7Accepted2/24ms820 KiB
8Accepted2/24ms928 KiB
9Accepted2/24ms880 KiB
10Accepted2/214ms2428 KiB
11Accepted1/11ms440 KiB
12Accepted2/26ms2356 KiB
13Accepted2/27ms2356 KiB
14Accepted2/26ms2432 KiB
15Accepted2/27ms2356 KiB
16Accepted2/27ms2380 KiB
17Wrong answer0/24ms2356 KiB
18Wrong answer0/16ms2328 KiB
19Wrong answer0/17ms2356 KiB
20Accepted1/16ms2360 KiB
21Wrong answer0/114ms2436 KiB
22Accepted1/114ms2436 KiB
23Wrong answer0/112ms2436 KiB
24Wrong answer0/112ms2360 KiB
25Accepted1/110ms2356 KiB
26Wrong answer0/113ms2368 KiB
27Wrong answer0/114ms2432 KiB
28Wrong answer0/110ms2432 KiB
29Accepted1/113ms2480 KiB
30Wrong answer0/110ms2356 KiB
31Wrong answer0/110ms2384 KiB
32Wrong answer0/112ms2432 KiB
33Wrong answer0/117ms2440 KiB
34Wrong answer0/114ms2436 KiB
35Wrong answer0/114ms2432 KiB
36Wrong answer0/114ms2428 KiB
37Wrong answer0/114ms2356 KiB
38Accepted1/114ms2360 KiB
39Accepted1/112ms2356 KiB
40Wrong answer0/114ms2356 KiB