当前位置:网站首页>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;
//
}边栏推荐
- 有没有完全自主的国产化数据库技术
- What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
- GifCam v7.0 极简GIF动画录制工具中文单文件版
- Pure QT version of Chinese chess: realize two-man, man-machine and network games
- Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
- RobotFramework入门(三)WebUI自动化之百度搜索
- tcpdump: no suitable device found
- Installation and use tutorial of cobaltstrike-4.4-k8 modified version
- Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
- Universal crud interface
猜你喜欢

Sign SSL certificate as Ca

RobotFramework入门(一)简要介绍及使用

Master data management theory and Practice

QT release exe software and modify exe application icon

Linear programming matlab

Introduction to robotframework (III) Baidu search of webui automation
![[network security interview question] - how to penetrate the test file directory through](/img/48/be645442c8ff4cc5417c115963b217.jpg)
[network security interview question] - how to penetrate the test file directory through

Apt installation ZABBIX

【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用

Apt installation ZABBIX
随机推荐
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
Self made CA certificate and SSL certificate using OpenSSL
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
07 单件(Singleton)模式
Codeforces 5 questions par jour (1700 chacune) - jour 6
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Add one to non negative integers in the array
MySQL advanced notes
XSS challenges bypass the protection strategy for XSS injection
Qt发布exe软件及修改exe应用程序图标
MySQL advanced notes
Network Security Learning - Web vulnerabilities (Part 1)
Single instance mode of encapsulating PDO with PHP in spare time
XSS challenges绕过防护策略进行 XSS 注入
2.11 simulation summary
Reverse repackaging of wechat applet
GifCam v7.0 极简GIF动画录制工具中文单文件版
力扣今日題-729. 我的日程安排錶 I
1. Dynamic parameters of function: *args, **kwargs
ERA5再分析资料下载攻略