-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDCEPC803_triptolondon.cpp
More file actions
47 lines (47 loc) · 1.45 KB
/
DCEPC803_triptolondon.cpp
File metadata and controls
47 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
int min(int a, int b);
int main()
{
int i,j,temp[25][25],dir[25][25],shrt[25][25],x,y,k,n,d;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&dir[i][j]);
if(dir[i][j]==-1)
{x=i;y=j;}
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&shrt[i][j]);
int count=0;
int flag=0;
for(d=shrt[x][y];d<=100;d++)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
temp[i][j]=dir[i][j];
temp[x][y]=d;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
temp[i][j]=min(temp[i][j],temp[i][k]+temp[k][j]);
flag=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(temp[i][j]!=shrt[i][j])
flag=1;
}
if(flag==0)
count++;
}
printf("%d\n",count);
return 0;
}
int min(int a, int b)
{
if(a<b)
return a;
else return b;
}