当前位置:网站首页>1087 all roads lead to Rome (30 points)
1087 all roads lead to Rome (30 points)
2022-07-03 04:55:00 【vs5】
The shortest path with multiple conditions , The data range is very small , Write a plain version directly .
With two map Save name corresponding number , Name corresponding to number
See the code
#include <iostream>
#include <unordered_map>
#include <cstring>
using namespace std;
const int N = 300;
int g[N][N],dis[N],disha[N],ha[N],path[N],cnt[N],res[N],n,m;
bool st[N];
string start,en = "ROM";
unordered_map<string,int>mp;
unordered_map<int,string>idx;
void dijkstra()
{
memset(dis,0x3f,sizeof dis);
dis[mp[start]] = 0;
res[mp[start]] = 1;
for(int i = 0; i < n; i ++)
{
int u = -1;
for(int j = 1; j <= n; j ++)
{
if(!st[j] && (u == -1 || dis[u] > dis[j])) u = j;
}
st[u] = true;
for(int j = 1; j <= n; j ++)
{
if(!st[j] && dis[j] > dis[u] + g[u][j])
{
dis[j] = dis[u] + g[u][j];// shortest path
disha[j] =disha[u] + ha[j];// Happiness
cnt[j] = cnt[u] + 1;// Path points
res[j] = res[u];// Number of shortest circuits
path[j] = u;// route
}
else if(dis[j] == dis[u] + g[u][j])
{
res[j] += res[u];
if(disha[j] < disha[u] + ha[j])
{
disha[j] = disha[u] + ha[j];
cnt[j] = cnt[u] + 1;
path[j] = u;
}
else if(disha[j] == disha[u] + ha[j])
if(cnt[j] > cnt[u] + 1)
{
cnt[j] = cnt[u] + 1;
path[j] = u;
}
}
}
}
}
void dfs(int u)
{
if(u == mp[start])
{
cout << idx[u];return ;
}
dfs(path[u]);
cout << "->" << idx[u];
}
int main()
{
cin >> n >> m >> start;
memset(g,0x3f,sizeof g);
mp[start] = 1;idx[1] = start;
for(int i = 2; i <= n ; i ++)
{
string s;int x;
cin >> s >> x;
mp[s] = i;idx[i] = s;ha[i] = x;
}
for(int i = 0; i < m; i ++)
{
string a,b;int x;
cin >> a >> b >> x;
g[mp[a]][mp[b]] = g[mp[b]][mp[a]] = x;
}
dijkstra();
cout << res[mp[en]] << ' ' << dis[mp[en]] << ' ' << disha[mp[en]] << ' ' << disha[mp[en]] / (cnt[mp[en]]) << endl;
dfs(mp[en]);
return 0;
} 边栏推荐
- MPM model and ab pressure test
- [research materials] 2021 China's game industry brand report - Download attached
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- Compile and decompile GCC common instructions
- 第十九届浙江省 I. Barbecue
- [Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
- Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
- Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)
- 1119 pre- and post order traversals (30 points)
猜你喜欢

MPM model and ab pressure test

RT thread flow notes I startup, schedule, thread

Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)

Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached

《牛客刷verilog》Part II Verilog进阶挑战

Thesis reading_ ICD code_ MSMN
![[luatos sensor] 2 air pressure bmp180](/img/88/2a6caa5fec95e54e3fb09c74ba8ae6.jpg)
[luatos sensor] 2 air pressure bmp180

【工具跑SQL盲注】

Uipath practice (08) - selector
随机推荐
50 practical applications of R language (36) - data visualization from basic to advanced
The reason why the entity class in the database is changed into hump naming
Symbol of array element product of leetcode simple problem
Notes | numpy-08 Advanced index
1114 family property (25 points)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
Blog building tool recommendation (text book delivery)
The least operation of leetcode simple problem makes the array increment
Notes | numpy-07 Slice and index
UiPath实战(08) - 选取器(Selector)
[SQL injection] joint query (the simplest injection method)
Apache MPM model and ab stress test
Handler understands the record
雇佣收银员(差分约束)
论文阅读_中文NLP_ELECTRA
Silent authorization login and registration of wechat applet
Market status and development prospects of the global IOT active infrared sensor industry in 2022
Thesis reading_ ICD code_ MSMN
Shell script Basics - basic grammar knowledge
Introduction to JVM principle