WaltVBAlston @ 2020-04-06 21:43:07
RT,感觉是没问题的。
二分答案转判定,最短路求check,感觉没问题啊。。。
哪位神犇帮忙康康好吗?
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn1 10001
#define maxn2 50001
bool ok=false;
ll d[maxn1];
bool flag[maxn1];
int u[maxn2],v[maxn2];
ll w[maxn2];
ll b;
int n,m;
int now[maxn1],before[maxn2];
ll cost[maxn1];
ll l,r,mid;
struct node
{
int index;
ll dis;
bool operator < (const node &x)const
{
return dis>x.dis;
}
};
priority_queue <node> q;
inline ll read()
{
ll num=0,z=1;
char c=getchar();
while(c>'9'||c<'0')
{
if(c=='-')
{
z=-1;
}
c=getchar();
}
while(c<='9'&&c>='0')
{
num=(num<<1)+(num<<3)+(c^48);
c=getchar();
}
return z*num;
}
bool check(int s)
{
for(int i=1;i<=n;i++)
{
d[i]=8223372036854775808;
flag[i]=false;
}
d[1]=0;
q.push((node){1,0});
while(!q.empty())
{
node x=q.top();
int k=x.index;
q.pop();
if(flag[k]==true)
{
continue;
}
flag[k]=true;
for(int i=now[k];i!=-1;i=before[i])
{
if(cost[v[i]]<=s)
{
if(d[v[i]]>d[k]+w[i])
{
d[v[i]]=d[k]+w[i];
q.push((node){v[i],d[v[i]]});
}
}
}
}
cout<<d[n]<<endl;
if(d[n]<=b)
{
ok=true;
return true;
}
return false;
}
int main()
{
n=read();
m=read();
b=read();
for(int i=1;i<=n;i++)
{
cost[i]=read();
now[i]=-1;
flag[i]=false;
d[i]=8223372036854775808;
}
for(int i=1;i<=m;i++)
{
u[i]=read();
v[i]=read();
w[i]=read();
before[i]=now[u[i]];
now[u[i]]=i;
}
for(int i=m+1;i<=2*m;i++)
{
u[i]=v[i-m];
v[i]=u[i-m];
w[i]=w[i-m];
before[i]=now[u[i]];
now[u[i]]=i;
}
l=0;
r=8223372036854775808;
while(l<r)
{
mid=(l+r)/2;
cout<<mid<<endl;
if(check(mid)==true)
{
r=mid;
}
else
{
l=mid+1;
}
}
if(ok==true)
{
if(check(l)==true)
{
printf("%lld",l);
}
else
{
printf("%lld",r);
}
}
else
{
printf("AFK");
}
return 0;
}
by tuzhewen @ 2020-04-06 22:08:15
因为您的
by WaltVBAlston @ 2020-04-06 22:09:26
@tuzhewen
Soga,我看看,谢了
by tuzhewen @ 2020-04-06 22:11:29
@Andy_2006 但是您的二分会
by tuzhewen @ 2020-04-06 22:15:31
by WaltVBAlston @ 2020-04-06 22:15:53
@tuzhewen
%%%
by WaltVBAlston @ 2020-04-06 22:23:41
@tuzhewen
AC了,谢
by tuzhewen @ 2020-04-06 22:24:36
@Andy_2006 您tql%%%(居然会dij和链式前向星QAQ)
by tuzhewen @ 2020-04-06 22:25:09
我只会spfa跟vec(还有邻接矩阵)/kk