uvaoj 208 how can i speed up my program
<p>why my program Time Limited Error?
because of the sort?
this is the question
<a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=108&amp;page=show_problem&amp;problem=144" rel="nofollow">link text</a></p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;cstring&gt;

using namespace std;

int map[22][44];
int book[22];
int total;
int sum;
int way[22];
int tails[22]; 
int tail; 

void init()
{
 memset(map,0,sizeof(map));
 memset(book,0,sizeof(book));
 sum =0;
 memset(way,0,sizeof(way));
 way[1]=1;
 memset(tails,0,sizeof(tails));
}

void sort()
{
 int t;
 for (int i=1;i&lt;=22;i++)
  {
   if (tails[i]==0)
    break;
   else
    {
     for (int j=1;j&lt;=tails[i]-1;j++)
      for (int k=j+1;k&lt;=tails[i];k++)
       {
        if (map[i][j] &gt; map[i][k])
         {
          t = map[i][j];
          map[i][j]=map[i][k];
          map[i][k]=t;
         }
       } 
    }
  }
}

void dfs(int x,int y)
{
 if ((x &lt; 1)||(x &gt; 22))
  return;
 if (book[x]==1)
  return;
 //printf("%d \n",x);
 if (x == total)
  {
   sum++;
   for (int i=1;i&lt;=y-1;i++)
   {
    printf("%d ",way[i]);
   }
   printf("%d",total);
   printf("\n");
   return;
  }
 tail = tails[x];
 for (int i=1;i&lt;=43;i++)
  {
   book[x]=1;
   way[y]=x;
   dfs(map[x][i],y+1);
   book[x]=0;
  } 
}

int main()
{
 int temp1,temp2;
 //freopen("ex.in","r",stdin);
 //freopen("ex.out","w",stdout);
 int c = 0;
 while(scanf("%d",&amp;total)!=EOF)
 {
 c++;
 printf("CASE ");
 printf("%d",c);
 printf(":");
 printf("\n");
 init();
 for (;;)
  {
   scanf("%d%d",&amp;temp1,&amp;temp2);
   if ((temp1 == 0)&amp;&amp;(temp2 == 0))
    break;
   else
    {
     tails[temp1]++;
     tail = tails[temp1];
     map[temp1][tail]=temp2;
     tails[temp2]++;
     tail = tails[temp2];
     map[temp2][tail]=temp1; 
    }
  }
  sort();
  dfs(1,1);
  printf("There are ");printf("%d",sum);printf(" routes from the firestation to streetcorner ");printf("%d",total);printf(".");
  printf("\n");
 }
 return 0;
}
</code></pre>
