Anonymous匿名者 @ 2019-07-23 07:27:58
WA 36分?
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();};
while(isdigit(c)){x=x*10+c-'0';c=getchar();};
return x*f;
}
typedef pair<int,int> pii;
priority_queue <pii,vector<pii>,greater<pii> > q;
const int maxn=10005,maxm=50005;
const int inf=0x3f3f3f3f;
struct edge{
int v,w,next;
}e[maxm];
int cnt,head[maxn];
int n,m,b;
int f[maxn],ff[maxn];
int ans=-1;
int dis[maxn];
bool vis[maxn];
int maxx=-1;
void add(int u,int v,int w)
{
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].next=head[u];
head[u]=cnt;
}
bool judge(int money)
{
if(money<f[1]||money<f[n])
return 0;
memset(dis,inf,sizeof(dis));
for(int i=1;i<=n;i++)
{
if(f[i]>money)
vis[i]=1;
else vis[i]=0;
}
dis[1]=0;
q.push(make_pair(dis[1],1));
while(!q.empty())
{
int u=q.top().second;
q.pop();
if(vis[u])
{
/*printf("%d yes\n",u);*/continue;
}
vis[u]=1;
for(int i=head[u];i;i=e[i].next)
{
int v=e[i].v;
if(!vis[v]&&dis[u]+e[i].w<dis[v])
{
dis[v]=dis[u]+e[i].w;
q.push(make_pair(dis[v],v));
}
}
}
//printf("shat %d %d\n",money,dis[n]);
//printf("fff money=%d f[1]=%d vis[1]=%d f[n]=%d vis[n]=%d\n",money,f[1],vis[1],f[n],vis[n]);
if(dis[n]<=b)
return 1;
else return 0;
}
void readdata()
{
n=read(),m=read(),b=read();
for(int i=1;i<=n;i++)
{
f[i]=read();
ff[i]=f[i];
}
maxx=max(f[1],f[n]);
sort(ff+1,ff+n+1);
/*for(int i=1;i<=n;i++)
printf("%d ",ff[i]);
printf("hello\n");*/
for(int i=1;i<=n;i++)
{
int a,b,c;
a=read(),b=read(),c=read();
add(a,b,c);
add(b,a,c);
}
int l=1,r=n;
while(l<=r)
{
int mid=l+r>>1;
if(ff[mid]>=maxx&&judge(ff[mid]))
{
//printf("on no %d\n",ff[mid]);
r=mid-1;
ans=ff[mid];
}
else l=mid+1;
}
if(ans!=-1)
printf("%d",ans);
else printf("AFK");
}
int main()
{
//freopen("sss.in","r",stdin);
readdata();
return 0;
}
by 铁锤 @ 2019-07-23 07:58:23
我也是昨天刚过了这道题,等下我把我的代码贴上,看一看是哪里错了
by 铁锤 @ 2019-07-23 07:58:54
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define maxn 100005
#define pii pair<int ,int >
priority_queue<pii ,vector<pii> ,greater<pii> > q;
int u1[maxn],v1[maxn],u2[maxn],v2[maxn],head[10005],nxt[maxn],vis[maxn];
ll w1[maxn],w2[maxn],b[10005],c[10005];
ll dis[10005];
int n,m;
ll hp;
const ll inf=1000000005;
inline int check(int x) {
if(x<b[1]||x<b[n]) return 0;
for(int i=1;i<=n;i++) {
dis[i]=inf;
}
for(int i=1;i<=n;i++) {
if(x<b[i])
vis[i]=1;
else
vis[i]=0;
}
dis[1]=0;q.push(make_pair(0,1));
while(!q.empty()) {
int u=q.top().second;q.pop();
if(vis[u])
continue;
vis[u]=1;
for(int i=head[u];i;i=nxt[i]) {
int v=v2[i];
if(dis[u]+w2[i]<dis[v]) {
dis[v]=dis[u]+w2[i];
q.push(make_pair(dis[v],v));
}
}
}
return dis[n]<=hp;
}
int main() {
scanf("%d%d%lld",&n,&m,&hp);
for(int i=1;i<=n;i++) {
scanf("%lld",&b[i]);
}
int cnt=0;
for(int i=1;i<=m;i++) {
scanf("%d%d%lld",&u1[i],&v1[i],&w1[i]);
cnt++;
nxt[cnt]=head[u1[i]];
head[u1[i]]=cnt;
v2[cnt]=v1[i],w2[cnt]=w1[i];
cnt++;
nxt[cnt]=head[v1[i]];
head[v1[i]]=cnt;
v2[cnt]=u1[i],w2[cnt]=w1[i];
}
ll l=1,r=1000000001,mid,ans=-1;
while(l<=r) {
mid=(l+r)>>1;
if(check(mid)) {
ans=mid;
r=mid-1;
}
else l=mid+1;
}
if(ans!=-1) printf("%lld",ans);
else printf("AFK");
return 0;
}
by 铁锤 @ 2019-07-23 07:59:09
@Anonymous匿名者
by 铁锤 @ 2019-07-23 08:01:52
您是不是也是二分出锅了?改一下试试
by Anonymous匿名者 @ 2019-07-23 08:23:51
@铁锤 二分是对的