比赛 |
HAOI2009 模拟试题4 |
评测结果 |
AAEE |
题目名称 |
服务器储存信息问题 |
最终得分 |
50 |
用户昵称 |
BYVoid |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2009-04-24 11:26:51 |
显示代码纯文本
/*
* Problem: HAOI2009 模拟4 servers
* Author: Guo Jiabao
* Time: 2009.4.24 11:14
* State: Unsolved
* Memo: Done
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
const int MAXN=4000,INF=0x7FFFFFF;
using namespace std;
int R[MAXN],dist[MAXN][MAXN],B[MAXN];
int N,M,Ans;
void init()
{
int i,a,b;
freopen("servers.in","r",stdin);
freopen("servers.out","w",stdout);
scanf("%d%d",&N,&M);
for (a=1;a<=N;a++)
for (b=1;b<=N;b++)
dist[a][b]=INF;
for (i=1;i<=N;i++)
{
scanf("%d",&R[i]);
dist[i][i]=0;
}
for (i=1;i<=M;i++)
{
scanf("%d%d",&a,&b);
scanf("%d",&dist[a][b]);
dist[b][a]=dist[a][b];
}
}
void floyd()
{
int i,j,k;
for (k=1;k<=N;k++)
for (i=1;i<=N;i++)
for (j=1;j<=N;j++)
if (dist[i][k] + dist[k][j] < dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
void solve()
{
int i,j,k;
floyd();
for (i=1;i<=N;i++)
{
for (j=1;j<=N;j++)
{
for (k=1;k<=N;k++)
{
if (dist[i][k] <= dist[i][j] && R[k]>R[j])
break;
}
if (k>N)
B[i]++;
}
Ans += B[i];
}
}
int main()
{
init();
solve();
printf("%d\n",Ans);
return 0;
}