Pagini recente » Cod sursa (job #2305732) | Cod sursa (job #1928724) | Cod sursa (job #1225461) | Cod sursa (job #381437) | Cod sursa (job #118391)
Cod sursa(job #118391)
using namespace std;
#include <stdio.h>
#include <vector>
#define Nmax 45002
#define Mmax 130002
int N,M,i,X,Y,S,E,Q;
vector<int> g[Nmax];
int st[Nmax];
char w[Nmax],u[Nmax],gasit;
void citire()
{
freopen("santa.in","r",stdin);
scanf("%d %d",&N,&M);
for (i=0;i<M;++i)
{
scanf("%d %d",&X,&Y);
g[X].push_back(Y);
g[Y].push_back(X);
}
scanf("%d %d %d",&S,&E,&Q);
fclose(stdin);
}
void lantz(int k)
{
vector<int>::iterator it;
if (st[k]==E) {
for (i=1;i<=k;++i)
u[st[i]]=1;
return;
}
for (it=g[st[k]].begin();it<g[st[k]].end();++it)
if (!w[*it])
{
w[*it]=1;
st[k+1]=*it;
lantz(k+1);
w[*it]=0;
}
}
void cauta(int k)
{
vector<int>::iterator it;
if (gasit) return;
if (k==X) {
gasit=1;
printf("%d\n",X);
for (i=1;i<=X;++i)
printf("%d ",st[i]);
return;
}
for (it=g[st[k]].begin();it<g[st[k]].end();++it)
if (!w[*it])
{
w[*it]=1;
st[k+1]=*it;
cauta(k+1);
w[*it]=0;
}
}
int main()
{
freopen("santa.out","w",stdout);
citire();
//toate lantzurile hamiltoniene posibile intre S si E
//n-ar trebui sa fie mai mult de 15
w[st[1]=S]=1;
lantz(1);
w[S]=0;
for (i=1,X=0;i<=N;++i)
if (u[i]) ++X;
//drumu lu maxdamage
w[st[1]=Q]=1;
cauta(1);
if (!gasit) printf("No chance");
fclose(stdout);
return 0;
}