Hello, please help me on the archive problem FNDY.
I feel it's a very easy problem but why wa??
i used fw for all pair sp and then sorted then printed..
here is my code..
please help.
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 25
#define INF 100000000
#define int long long
int p[N][N];
void print(int i,int j)
{
if(i!=j) print(i,p[j]);
printf("\t%lld",j+1);
}
main()
{
char s[80000],*q;
int a[N][N],i,j,cas,z,n,m,b[N],e,k,h;
gets(s);
sscanf(s,"%lld",&cas);
gets(s);
for(z=0;z<cas;z++)
{
if(z) printf("\n"),gets(s);
printf("Org\tDest\tTime\tPath\n");
gets(s);
sscanf(s,"%lld",&n);
for(i=0;i<n;i++)
{
gets(s);
q=strtok(s," ");
if(!q) continue;
j=0;
sscanf(q,"%lld",&a[j++]);
while(q)
{
q=strtok(NULL," ");
if(!q) break;
sscanf(q,"%lld",&a[j++]);
}
}
for(i=0;i<n;i++) for(j=0;j<n;j++) p[j]=i;
for(i=0;i<n;i++) for(j=0;j<n;j++) if(a[j]==-1) a[j]=INF;
for(k=0;k<n;k++)
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(((a[k]+a[k][j])<a[j]) && a[k]!=INF && a[k][j]!=INF)
a[i][j]=a[i][k]+a[k][j],p[i][j]=p[k][j];
gets(s);
q=strtok(s," ");
sscanf(q,"%lld",&e);e--;
m=0;
while(q)
{
q=strtok(NULL," ");
if(!q) break;
sscanf(q,"%lld",&b[m]);
b[m]--;m++;
}
for(i=0;i<m-1;i++)
{
h=i;
for(j=i+1;j<m;j++)
if(a[b[j]][e]<a[b[h]][e])
h=j;
j=b[h];b[h]=b[i];b[i]=j;
}
if(!m) continue;
for(i=0;i<m;i++)
{
printf("%lld\t%lld\t%lld",b[i]+1,e+1,a[b[i]][e]);
print(b[i],e);
printf("\n");
}
}
return 0;
}[/c]
i am waiting for your help.
Archive problem 2367 , FNDY, plz help, getting wa
Moderator: Board moderators
Archive problem 2367 , FNDY, plz help, getting wa
"Everything should be made simple, but not always simpler"
-
- Experienced poster
- Posts: 202
- Joined: Fri Mar 22, 2002 2:00 am
- Location: Chittagong. CSE - CUET
- Contact:
Hmm... Anupam! as pointed out by Faizur today....that there should be a discussion topic i.e. section about those archieve problems!
You know many are joining in the ICPC Regionals and there are taking lots of preparation for that....but when they are trying to solve Archieve problems they won't find such help and advice of the experienced programmers as like vol. section's threads.....so fpnc now it's you time to look about this matter and take proper step
You know many are joining in the ICPC Regionals and there are taking lots of preparation for that....but when they are trying to solve Archieve problems they won't find such help and advice of the experienced programmers as like vol. section's threads.....so fpnc now it's you time to look about this matter and take proper step

