150972025-02-12 19:36:23MrkzFertőzési sorozat (50 pont)cpp17Wrong answer 0/506ms1384 KiB
#include <iostream>
//#include <fstream>
using namespace std;
int N,K,M,db,St[500];
int fertozes[500], kapcsolat[500][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;
    for(int i=1;i<=db;i++)
        cout<<fertozes[i]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms508 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/02ms820 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/21ms592 KiB
6Wrong answer0/22ms820 KiB
7Wrong answer0/21ms820 KiB
8Wrong answer0/22ms820 KiB
9Wrong answer0/23ms900 KiB
10Wrong answer0/22ms1332 KiB
11Wrong answer0/11ms408 KiB
12Wrong answer0/22ms1332 KiB
13Wrong answer0/22ms1332 KiB
14Wrong answer0/22ms1332 KiB
15Wrong answer0/22ms1332 KiB
16Wrong answer0/22ms1332 KiB
17Wrong answer0/22ms1332 KiB
18Wrong answer0/12ms1384 KiB
19Wrong answer0/12ms1332 KiB
20Wrong answer0/12ms1336 KiB
21Wrong answer0/13ms1332 KiB
22Wrong answer0/16ms1228 KiB
23Wrong answer0/12ms1336 KiB
24Wrong answer0/16ms1332 KiB
25Wrong answer0/12ms1336 KiB
26Wrong answer0/12ms1144 KiB
27Wrong answer0/12ms1332 KiB
28Wrong answer0/14ms1332 KiB
29Wrong answer0/12ms1332 KiB
30Wrong answer0/12ms1332 KiB
31Wrong answer0/12ms1332 KiB
32Wrong answer0/12ms1372 KiB
33Wrong answer0/12ms1332 KiB
34Wrong answer0/13ms1332 KiB
35Wrong answer0/12ms1332 KiB
36Wrong answer0/14ms1332 KiB
37Wrong answer0/13ms1332 KiB
38Wrong answer0/14ms1332 KiB
39Wrong answer0/12ms1260 KiB
40Wrong answer0/13ms1332 KiB