社区讨论
所有优化都开了,还是T了最后一个点
P1396营救参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mi6hm4nv
- 此快照首次捕获于
- 2025/11/20 05:01 4 个月前
- 此快照最后确认于
- 2025/11/20 05:01 4 个月前
CPP
#include <bits/stdc++.h>
#define M 200001
#define INF 2147483646
using namespace std;
int n,m,s,t,cnt=1,head[M];
struct Street{int to,next,val;}X[M];
int dis[M];
inline int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=-1,ch=getchar();
while (ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*w;
}
void add(int u,int v,int w)
{
X[cnt].to=v;
X[cnt].val=w;
X[cnt].next=head[u];
head[u]=cnt++;
X[cnt].to=u;
X[cnt].val=w;
X[cnt].next=head[v];
head[v]=cnt++;
return;
}
void spfa(int t)
{
for(int i=head[t];i;i=X[i].next)
if(dis[X[i].to]>max(dis[t],X[i].val))
{
dis[X[i].to]=max(dis[t],X[i].val);
spfa(X[i].to);
}
return;
}
int main()
{
n=gi();m=gi();s=gi();t=gi();
for(int i=1;i<=m;i++)
{
int u=gi(),v=gi(),w=gi();
add(u,v,w);
}
for(int i=1;i<=n;i++)
if(i!=s)
dis[i]=INF;
spfa(s);
printf("%d",dis[t]);
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...