Gae_Blog @ 2018-11-03 16:02:50
是check()函数出现的问题,似乎只有限定fm为(f[i])max的时候check才会成功。恳请dalao帮忙指点!
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<cstdlib>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define maxn 10000+100
#define maxm 50000<<1
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
LL n,m,f[maxn],b,ans,f1,fn,dis[maxn];
bool vis[maxn];
struct edge{
int u,v,c,nxt;
}g[maxm];
struct node{
int u;LL d;
bool operator < (const node& a) const{
return this->d<a.d;
}
};
int pre[maxn],cnt;
inline void edgeadd(int u,int v,int c)
{
g[++cnt].u=u;
g[cnt].v=v;
g[cnt].c=c;
g[cnt].nxt=pre[u];
pre[u]=cnt;
}
LL read()
{
char c=getchar();int x=0;
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x;
}
bool check(long long fm)
{
memset(vis,0,sizeof(vis));
memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;i++)
if(f[i]>fm) vis[i]=1;
dis[1]=0;
priority_queue<node> q;
q.push((node){1,dis[1]});
while(!q.empty())
{
node x=q.top();q.pop();
int u=x.u;
if(vis[u]) continue;
vis[u]=1;
for(int i=pre[u];i;i=g[i].nxt)
{
int v=g[i].v,c=g[i].c;
if(f[v]>fm) continue;
if(dis[v]>dis[u]+c)
{
dis[v]=dis[u]+c;
q.push((node){v,dis[v]});
}
}
}
ans=dis[n];
return (b>ans);
}
int lower(int l,int r,int key)
{
while(l<=r)
{
int mid=(l+r)>>1;
if(f[mid]>key) r=mid-1;
if(f[mid]==key) return mid;
if(f[mid]<key) l=mid+1;
}
return -1;
}
int main()
{
freopen("in.txt","r",stdin);
n=read();m=read();b=read();
for(int i=1;i<=n;i++)
{f[i]=read();if(i==1) f1=f[i];if(i==n) fn=f[i];}
f1=max(f1,fn);
for(int i=1;i<=m;i++)
{
int u=read(),v=read(),c=read();
if(u==v) continue;
edgeadd(u,v,c);edgeadd(v,u,c);
}
sort(f+1,f+1+n);
int l=lower(1,n,f1),r=n;
while(l<r)
{
int mid=(l+r)>>1;
if(check(f[mid])) r=mid;
else l=mid+1;
}
if(!check(f[r])) cout<<"AFK";
else cout<<f[r];
return 0;
}
by Gae_Blog @ 2018-11-03 16:33:44
把INF加大到9999999,后63分
by Gae_Blog @ 2018-11-03 17:10:38
好神奇,把反了的重载运算符改回来,去掉=0的情况还是63...
by 胡尔克HULK @ 2019-01-30 19:19:31
兄弟,直接输出AFK也是27分