当前位置:网站首页>1003 emergency (25 points), "DIJ deformation"
1003 emergency (25 points), "DIJ deformation"
2022-07-06 02:54:00 【Yang tree Yang tree】
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define dd double
#define PII pair<int,int>
#define int long long
using namespace std;
const dd eps = 1e-6;
const int mod = 1000003;
const int N = 1e3+10;
int n,m;
int c1,c2;
int cnt[N],sum[N];
int weight[N];
// cnt[j] Deposit is j The number of shortest circuits to the starting point .
// sum[j] Deposit is j The largest number of people on the shortest path to the starting point
/*
n - Number of cities
m - The number of roads
c1 and c2 Cities that must be rescued
*/
//#define int long long
const int INF = 0x3f3f3f3f3f3f3f3f;
int g[N][N], dist[N]; // Dense graphs are stored in adjacency matrices
bool st[N];
void dijkstra()
{
// The starting point is initialized to 0, Other points are initialized to infinity (INF)
memset(dist, 0x3f, sizeof dist);
dist[c1] = 0;
// The starting quantity is 1
cnt[c1]=1;
// Starting number is w1
sum[c1]=weight[c1];
for(int i = 1; i <= n; i++)
{
// Find the point in which the shortest circuit is not currently determined The shortest distance
int t = -1;
for(int j = 0; j < n; j++)
if(!st[j] && (t == -1 || dist[t] > dist[j])) t = j;
// use t Update other points
for(int j = 0; j < n; j++)
{
if(dist[j]>dist[t]+g[t][j])
{
dist[j]=dist[t]+g[t][j];
cnt[j]=cnt[t];
sum[j]=sum[t]+weight[j];
}
else if(dist[j]==dist[t]+g[t][j])
{
cnt[j]+=cnt[t];
sum[j]=max(sum[j],sum[t]+weight[j]);
}
}
// t The shortest circuit has been determined
st[t] = true;
}
// if INF It means there is no way
}
signed main()
{
// Input part
memset(g,0x3f,sizeof(g));
cin>>n>>m>>c1>>c2;
for(int i=0;i<n;i++)
{
cin>>weight[i];
}
for(int i=0;i<m;i++)
{
int a,b,c;
cin>>a>>b>>c;
g[a][b]=g[b][a]=min(g[a][b],c);
}
dijkstra();
cout<<cnt[c2]<<" "<<sum[c2]<<endl;
return 0;
//
}边栏推荐
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23](/img/72/a80ee7ee7b967b0afa6018070d03c9.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23

力扣今日題-729. 我的日程安排錶 I

Reverse repackaging of wechat applet

Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands

XSS challenges bypass the protection strategy for XSS injection

2345 file shredding, powerful file deletion tool, unbound pure extract version
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17](/img/85/2635afeb2edeb0f308045edd1f3431.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17

【Unity3D】GUI控件

MySQL advanced notes

【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
随机推荐
【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
RobotFramework入门(二)appUI自动化之app启动
深度解析链动2+1模式,颠覆传统卖货思维?
如何精准识别主数据?
Patch NTP server at the beginning of DDoS counterattack
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
MySQL winter vacation self-study 2022 11 (7)
1. Dynamic parameters of function: *args, **kwargs
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Codeworks 5 questions per day (1700 average) - day 6
Redis delete policy
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
Atcoder beginer contest 233 (a~d) solution
不赚钱的科大讯飞,投资价值该怎么看?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
张丽俊:穿透不确定性要靠四个“不变”
Yyds dry inventory comparison of several database storage engines
Trends in DDoS Attacks
微服务注册与发现
Data and Introspection__ dict__ Attributes and__ slots__ attribute