ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1205. By the Underground or by Foot?

Runtime error (access violation)Test#3
Posted by Khujamurod97 19 Oct 2017 20:32
Help!
/*
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int const N=901;
float d[N][N];
int l[N][N];
int x[N],y[N];
int v1,v2;
int n;
float INF=999999999;
float dist(int i, int j){
return pow(powf(x[i]-x[j], 2) + powf(y[i] - y[j],2), 1./2);
}
void dp(){
for (int k=0; k<n; ++k)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
if (d[i][k] < INF && d[k][j] < INF)
if( d[i][j] > d[i][k] + d[k][j]){
d[i][j] = d[i][k] + d[k][j];
l[i][j]=k;
}
}
float distance(int x1, int y1, int x2, int y2){
return powf(powf(x1-x2, 2) + powf(y1 - y2,2), 1./2);
}
int a[100001];
int q=0;
int rec(int i, int j){
//if(i==j)
if(q>100000)return 0;
if(l[i][j]==-1){
a[q++]=i;
return 1;
}

return rec(i,l[i][j])+rec(l[i][j],j);

}
int main() {
int x1,x2,y2,y1;

scanf("%d%d", &v1, &v2);
scanf("%d", &n);
for( int i = 0; i < n; i ++){
scanf("%d%d", x+i, y+i);
}

for(int i = 0; i<n;i++)
for(int j = 0; j<n;j++){
if(i == j) d[i][j] = 0;
else d[i][j] = INF;
l[i][j]=-1;
}

int xx, yy;
while(1){
scanf("%d%d", &xx, &yy);
if(xx == 0 && yy == 0)break;
xx--;yy--;
d[yy][xx] = d[xx][yy] = dist(xx, yy);
}

dp();

scanf("%d%d", &x1, &y1);
scanf("%d%d", &x2, &y2);

float len = distance(x1,y1,x2,y2)/v1;
int ii=-1,jj=-1;

for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(i != j){
float l=distance(x1,y1,x[i],y[i])/v1;
l+=distance(x[j],y[j],x2,y2)/v1+d[i][j]/v2;
if(len > l){
len=l;
ii=i;
jj=j;
}
}
}

if(ii == -1){
printf("%.7f\n0", len);
return 0;
}
printf("%.7f\n", len);
int k=rec(ii,jj);
printf("%d", k+1);
a[q++]=jj;
for(int i=0;i<q;i++){
printf(" %d", a[i]+1);
}

}
*/