#include<iostream>
using namespace std;
const int MAX=2147483647;
int n,m;
int t1,t2,len;
int map[1005][1005];
int ans[1005];
int isvisit[1005];
int answer;
void Dijkstra();
int DFS(int k);
int main()
{
while(cin>>n,n)
{
answer=0;
memset(isvisit,-1,sizeof(isvisit));
for(int i=1;i<=n;i++)
{
ans[i]=MAX;
for(int j=1;j<=n;j++)
{
map[i][j]=MAX;
}
}
cin>>m;
for(i=0;i<m;i++)
{
cin>>t1>>t2>>len;
if(map[t1][t2]>len)
map[t1][t2]=map[t2][t1]=len;
}
Dijkstra();
// for(i=1;i<=n;i++)
// {
// cout<<ans[i]<<endl;
// }
cout<<DFS(1)<<endl;
}
return 0;
}
void Dijkstra()
{
int visit[1005]={0};
int k;
ans[2]=0;
for(int i=1;i<=n;i++)
{
k=-1;
for(int j=1;j<=n;j++)
{
if(!visit[j] && ( k==-1 || ans[j]<ans[k]) )
k=j;
}
visit[k]=1;
for(j=1;j<=n;j++)
{
if(!visit[j] && ans[j]>ans[k]+map[k][j] && map[k][j]!=MAX)
ans[j]=ans[k]+map[k][j];
}
}
}
int DFS(int k)
{
int temp=0;
if(isvisit[k]!=-1)
return isvisit[k];
if(k==2)
{
return 1;
}
for(int i=1;i<=n;i++)
{
if(map[k][i]!=MAX && ans[k]>ans[i])
temp+=DFS(i);
}
isvisit[k]=temp;
return temp;
}
分享到:
相关推荐
acm hdu as easy as a+b
现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。 Input 本题目包含多组测试数据,请处理到文件结束。 每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。 Output 请在一行里面...
hdu 1695 GCD(欧拉函数+容斥原理).docx
本人准备2020年保研机试时刷的题目(虽然最后机试取消了,...来自某中流985,在HDU和vjudge平台上大概刷了400道。本文件地图(excel表格)包含了绝大部分我刷过的题目,笔记中具有思路、代码、总结和心得。 大佬勿入!
ACM题库,一些题目和答案,以及解题报告,传上来共享
NULL 博文链接:https://128kj.iteye.com/blog/1716470
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input...
300+ AC 代码 。 大数 , 线段树 , 字符串 , dp.....
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
For a positive integer n, let’s denote function f(n,m) as the m-th smallest integer x that x>n and gcd(x,n)=1. For example, f(5,1)=6 and f(5,5)=11. You are given the value of m and (f(n,m)?n)⊕n,...
搜索 dfs 解题代码 hdu1241
hdu 1574 passed sorce
杭电OnlineJudge 200-2099的解题报告
HDU的一题........HDU DP动态规
hdu2101AC代码