L2-001 紧急救援
1.G. Vlad and Trouble at MIT2.P2899 [USACO08JAN] Cell Phone Network G3.Watering an Array4.P2055 [ZJOI2009] 假期的宿舍5.T432579 大西洋船王6.T432580 星云 hard ver.7.P7072 [CSP-J2020] 直播获奖8.E - Insert or Erase9.D - String Bags10.P2671 [NOIP2015 普及组] 求和11.P1884 [USACO12FEB] Overplanting S12.F. Microcycle13.E. Increasing Subsequences__214.G. Path Prefixes15.F. Rudolf and Imbalance16.P1355 神秘大三角17.[ARC172A] Chocolate18.F. 0, 1, 2, Tree!19.E. Nearly Shortest Repeating Substring20.P1354 房间最短路问题21.P3258 [JLOI2014] 松鼠的新家22.P3052 [USACO12MAR] Cows in a Skyscraper G23.P1337 [JSOI2004] 平衡点 / 吊打XXX24.P3745 [六省联考 2017] 期末考试25.D. Inaccurate Subsequence Search26.E. Long Inversions27.C. Deep Down Below28.C. Rings29.F. Unfair Game30.C. Inversion Graph31.D. Cross Coloring32.D2. Set To Max (Hard Version)33.C. Array Game34.F. Alex's whims35.Queue Sort36.P10252 线性变换37.P10288 [GESP样题 八级] 区间38.P2161 [SHOI2009] 会场预约
39.L2-001 紧急救援
40.L2-002 链表去重41.L2-013 红色警报42.L2-014 列车调度43.L2-022 重排链表44.L2-023 图着色问题45.L2-039 清点代码库46.L2-034 口罩发放47.L3-037 夺宝大赛48.仓库规划49.因子化简50.C. Torn Lucky Ticket51.俄罗斯方块52.F. Cutting Game53.D. Prefix Permutation Sums54.P3304 [SDOI2013] 直径题解
确定起点和终点,求救援人数最长,路径最短的路径,只需要集群算法中优先队列中重载比较符修改一下就就行,由于数据量很小,所以输出路径的时候搜索就行(最优解唯一)
code
#include<bits/stdc++.h>
using namespace std;
struct node
{
int to,val;
};
vector<node> G[505];
int people[505]={0};
int help[505]={0};
int dis[505];
int path[505]={0};
int vis[505]={0};
stack<int> st;
int flag=0;
int n,m,s,d;
struct fresh
{
int to,pre,val;
bool operator<(const fresh &b)const
{
if(val!=b.val)return val>b.val;//dis
else return help[pre]+people[to]<help[b.pre]+people[b.to];//help
}
};
void ss(int walk,int cure,int now)
{
if(walk==0&&cure==0)
{
if(now!=d) return;
flag=1;
st.push(now);
return ;
}
if(walk<=0||cure<=0||now==d) return;
for(auto next:G[now])
{
int to=next.to,val=next.val;
if(!vis[to])
{
vis[to]=1;
ss(walk-val,cure-people[to],to);
vis[to]=0;
}
if(flag)
{
st.push(now);
return ;
}
}
}
int main()
{
memset(dis,0x3f,sizeof dis);
cin>>n>>m>>s>>d;
for(int i=0;i<n;i++) cin>>people[i];
for(int i=1;i<=m;i++)
{
int x,y,c;
cin>>x>>y>>c;
G[x].push_back({y,c});
G[y].push_back({x,c});
}
priority_queue<fresh> q;
q.push({s,s,0});
path[s]=1;
while(q.size())
{
int now=q.top().to,pre=q.top().pre,val=q.top().val;
q.pop();
if(dis[now]<val) continue;
else if(dis[now]==val)
{
path[now]+=path[pre];
continue;
}
dis[now]=val;
path[now]=path[pre];
help[now]=help[pre]+people[now];
for(auto next:G[now]) q.push({next.to,now,next.val+dis[now]});
}
cout<<path[d]<<" "<<help[d]<<endl;
ss(dis[d],help[d]-people[s],s);
while(st.size())
{
cout<<st.top();
st.pop();
if(st.size()) cout<<" ";
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~