比赛 |
20100419 |
评测结果 |
C |
题目名称 |
城市规划 |
最终得分 |
0 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-04-19 10:38:20 |
显示代码纯文本
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 103,Inf = 100000000;
int N;
int Dis[maxn][maxn],W[maxn][maxn];
bool T[maxn][maxn];
int min(int a,int b)
{
return a<b?a:b;
}
void prep()
{
scanf("%d",&N);
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
{
scanf("%d",&W[i][j]);
Dis[i][j] = W[i][j]<=0?Inf : W[i][j];
}
for (int i=1; i<=N; i++) Dis[i][i] = 0;
}
bool Can(int x,int y)
{
if (W[x][y]<=0) return false;
bool Ok = false;
for (int i=1; i<=N; i++)
{
if (Dis[i][x]+W[x][y]==Dis[i][y] || Dis[i][y]+W[y][x]==Dis[i][x])
{
Ok = true; break;
}
}
if (!Ok) return false;
for (int i=1; i<=N; i++)
{
if (i==x || i==y) continue;
if (Dis[x][i]+Dis[i][y]==W[x][y])
return false;
}
return true;
}
void work()
{
for (int k=1; k<=N; k++)
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
{
if (k==i || k==j || i==j) continue;
Dis[i][j] = min(Dis[i][j],Dis[i][k]+Dis[k][j]);
}
for (int i=1; i<N; i++)
for (int j=i+1; j<=N; j++)
{
if (Can(i,j))
T[i][j] = T[j][i] = true;
}
for (int i=1; i<=N; i++)
{
for (int j=1; j<N; j++)
printf("%d ",T[i][j]);
printf("%d\n",T[i][N]);
}
}
int main()
{
freopen("cityroad.in","r",stdin);
freopen("cityroad.out","w",stdout);
prep();
work();
return 0;
}