151012025-02-12 20:16:12MrkzFertőzési sorozat (50 pont)cpp11Wrong answer 0/506ms1524 KiB
#include <iostream>
//#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
int N,K,M,db,St[500];
int kapcsolat[500][500];
vector<int> fertozes(500);
void beolvas(){
    //ifstream f("kapcsolatok.in");
    cin>>N>>M>>K;
    for(int i=1;i<=K;i++)
        cin>>fertozes[i];
    for(int i=1;i<=M;i++){
        int x,y;
        cin>>x>>y;
        kapcsolat[x][y]=1;
        kapcsolat[y][x]=1;
    }
    //f.close();
}
bool vanMegoldas(int szint){
    if(szint==0)
        return false;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=K;j++)
        if(kapcsolat[i][fertozes[1]]==1 || kapcsolat[fertozes[1]][i]==1)
            return true;
    }
    return false;
}
bool Jo(int szint){
    if(szint>N)
        return false;
    for(int i=1;i<=K;i++)
        if(fertozes[i]==St[szint])
            return false;
     for(int i=1;i<=szint-1;i++)
        if(St[szint]==St[i])
            return false;
    return(kapcsolat[St[szint]][fertozes[1]]==1 || kapcsolat[fertozes[1]][St[szint]]==1);
}
void Back(int szint){
    if(vanMegoldas(szint-1)){
        db++;

            for(int j=K+1;j>1;j--){
                fertozes[j]=fertozes[j-1];
            }
            K++;
        fertozes[1]=St[szint-1];
    }
    for(int i=1;i<=N;i++){
        St[szint]=i;
        if(Jo(szint))
            Back(szint+1);
    }
}
int main()
{
    beolvas();
    Back(1);
    cout<<db<<endl;
     sort(fertozes.begin()+1, fertozes.begin() + db+1);
    for(int i=1;i<=db;i++)
        cout<<fertozes[i]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/02ms820 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/21ms608 KiB
6Wrong answer0/21ms844 KiB
7Wrong answer0/21ms820 KiB
8Wrong answer0/22ms820 KiB
9Wrong answer0/23ms820 KiB
10Wrong answer0/22ms1380 KiB
11Wrong answer0/11ms552 KiB
12Wrong answer0/22ms1336 KiB
13Wrong answer0/22ms1332 KiB
14Wrong answer0/22ms1332 KiB
15Wrong answer0/22ms1332 KiB
16Wrong answer0/22ms1336 KiB
17Wrong answer0/22ms1332 KiB
18Wrong answer0/12ms1332 KiB
19Wrong answer0/12ms1332 KiB
20Wrong answer0/12ms1332 KiB
21Wrong answer0/13ms1288 KiB
22Wrong answer0/16ms1332 KiB
23Wrong answer0/12ms1332 KiB
24Wrong answer0/16ms1380 KiB
25Wrong answer0/12ms1524 KiB
26Wrong answer0/12ms1332 KiB
27Wrong answer0/13ms1332 KiB
28Wrong answer0/14ms1524 KiB
29Wrong answer0/12ms1316 KiB
30Wrong answer0/12ms1208 KiB
31Wrong answer0/12ms1332 KiB
32Wrong answer0/12ms1332 KiB
33Wrong answer0/13ms1332 KiB
34Wrong answer0/13ms1524 KiB
35Wrong answer0/12ms1332 KiB
36Wrong answer0/14ms1336 KiB
37Wrong answer0/13ms1336 KiB
38Wrong answer0/14ms1176 KiB
39Wrong answer0/12ms1332 KiB
40Wrong answer0/13ms1332 KiB