当前位置:网站首页>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;
//
}
边栏推荐
- Redis installation
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
- XSS challenges绕过防护策略进行 XSS 注入
- MySQL winter vacation self-study 2022 11 (8)
- Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
- How to improve the enthusiasm of consumers when the member points marketing system is operated?
- Sign SSL certificate as Ca
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
- 2.12 simulation
- [ruoyi] enable Mini navigation bar
猜你喜欢
[ruoyi] set theme style
XSS challenges绕过防护策略进行 XSS 注入
My C language learning records (blue bridge) -- files and file input and output
Communication between microservices
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Introduction to robotframework (III) Baidu search of webui automation
Sign SSL certificate as Ca
Linear programming matlab
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
ReferenceError: primordials is not defined错误解决
随机推荐
Introduction to robotframework (III) Baidu search of webui automation
Zhang Lijun: penetrating uncertainty depends on four "invariants"
MySQL advanced notes
Linear programming matlab
My C language learning record (blue bridge) -- on the pointer
[pointer training - eight questions]
Briefly describe the implementation principle of redis cluster
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
球面透镜与柱面透镜
MySQL winter vacation self-study 2022 11 (7)
What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
Is there a completely independent localization database technology
2.13 simulation summary
The difference between sizeof and strlen in C language
codeforces每日5題(均1700)-第六天
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Pure QT version of Chinese chess: realize two-man, man-machine and network games
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
Data and Introspection__ dict__ Attributes and__ slots__ attribute
How to read excel, PDF and JSON files in R language?