您的位置:首页 > 其它

uva208

2014-05-13 10:41 281 查看
TLE

谷歌说要先搜索一下标记一下那些路是可以到终点的

仔细一想也是啊这样可以了

//www.docin.com/p-540449152.html
#include <iostream>
#include<cstring>
//#defien LOCAK
using namespace std;
int ma[22][22],v[22],k=0,tot=0,ans[22],n,m,vis[22];
void DFS(int cur)
{
for(int i=1;i<=m;i++)
if(ma[cur][i]&&!vis[i])
{
vis[i]=1;
DFS(i);
}
}
void dfs(int cur)
{
if(cur==n)
{
tot++;
cout<<'1';
for(int i=0;i<k;i++)
cout<<" "<<ans[i];
cout<<endl;
}
else for(int i=2;i<=m;i++)
if(vis[i]&&ma[cur][i]&&!v[i])
{
ans[k++]=i;
v[i]=1;
dfs(i);
v[i]=0;
k--;
}
}
int main()
{
#ifdef LOCAK
freopen("input.txt","r",stdin);
freoprn("output.txt","w",stdout);
#endif // LOCAK
int x,y,CASE=1;
while(cin>>n)
{
m=0;
while(cin>>x>>y,x+y){m=max(x,m);m=max(y,m);
ma[x][y]=ma[y][x]=1;}
cout<<"CASE "<<CASE++<<":"<<endl;
DFS(n);
dfs(1);
cout<<"There are "<<tot<<" routes from the firestation to streetcorner "<<n<<"."<<endl;
memset(ma,0,sizeof(ma));
memset(v,0,sizeof(v));
memset(vis,0,sizeof(vis));
tot=0;
}
return 0;
}




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: