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 Komodo @ 2020-04-06 21:45:58
check没开long long
by Komodo @ 2020-04-06 21:46:29
@Andy_2006 其他有没有错不知道
by WaltVBAlston @ 2020-04-06 21:50:58
样例都过不去,。。
by tuzhewen @ 2020-04-06 21:59:12
@Andy_2006 您的ok在二分的时候不用初始化吗……
by WaltVBAlston @ 2020-04-06 22:00:44
@tuzhewen
不用。那个是表示有没有解得。
by tuzhewen @ 2020-04-06 22:02:04
cout<<d[n]是个啥
by WaltVBAlston @ 2020-04-06 22:02:52
@tuzhewen
调试,按照这个最短路结果应该不会出问题的。
by tuzhewen @ 2020-04-06 22:03:40
@Andy_2006 我去调一下QAQ
by WaltVBAlston @ 2020-04-06 22:04:01
@tuzhewen
谢谢您了
by tuzhewen @ 2020-04-06 22:07:33
@Andy_2006 您把check的参数换成ll