Hi,
i have no idea about this problem,
can anyone else help me?
Moderator: Board moderators

Removed after AC.

for i = 1 to N
for j = 1 to N
if there is an edge from i to j
dist[0][i][j] = the length of the edge from i to j
else
dist[0][i][j] = INFINITY
for k = 1 to N
for i = 1 to N
for j = 1 to N
dist[k][i][j] = min(dist[k-1][i][j], dist[k-1][i][k] + dist[k-1][k][j])#include<iostream>
using namespace std;
int dist[2][100][100]={0};bool Array1[100][100];int N,root,dest;
void Commandos (int x,int counter,int a)
{
int q=0;
for (int i=0;i<N;i++)
{
if (i==x)
continue;
if (Array1[x][i]==true && Array1[i][x]==true && dist[a][x][i]==0)
{
Array1[x][i]=false;counter++;
if (a==1)
dist[a][dest][i]=counter;
else
dist[a][root][i]=counter;
Commandos(i,counter,a);
counter--;
}
else
q++;
}
if (q==N-1)
return;
}
int main()
{
int count=0,counter=0,T,R;
scanf("%d",&T);
for (int z=0;z<T;z++)
{
counter=0;count++;bool Array[100][100]={false};
scanf("%d\n%d",&N,&R);
for (int y=0;y<R;y++)
{
scanf("%d %d",&root,&dest);
Array[root][dest]=true;
Array[dest][root]=true;
}
scanf("%d\n%d",&root,&dest);
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
Array1[i][j]=Array[i][j];
Commandos(dest,0,1);
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
Array1[i][j]=Array[i][j];
Commandos(root,0,0);
for (int i=0;i<N;i++)
if (counter<dist[0][root][i]+ dist[1][dest][i])
counter=dist[0][root][i]+ dist[1][dest][i];
printf("Case %d: %d\n",count,counter);
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
{
dist[0][i][j]=0;
dist[1][i][j]=0;
}
}
return 0;
}3
4
3
0 1
2 1
1 3
0 3
2
1
0 1
1 0
4
3
0 1
2 1
1 3
0 0
Case 1: 4
Case 2: 1
Case 3: 4
Hi I try to solve this problem
But i get wa...........
I use two BFS...
Here is my code..............
PLZ help me..........![]()
![]()
![]()
![]()
Cut after ACC.......
Some one PLZ help me .........
![]()
![]()
![]()
Its boring no body help me
PLZ some one help me![]()
![]()
![]()
Users browsing this forum: No registered users and 0 guests