哈哈哈哈哈哈RE了哈哈哈哈哈哈

P1462 通往奥格瑞玛的道路

iMya_nlgau @ 2020-03-12 21:39:00

我已经快疯了 10RE 1AC

讨论版里好多人都是10RE

哪个dalao能帮忙康康代码

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=1e4+10;
const int maxm=1e5+10;
struct Edge{
    int to,w,next;
}edge[maxm];
int head[maxn],cnt;
void Init(){
    for(int i=0;i<maxn;i++) head[i]=-1;
    for(int i=0;i<maxm;i++) edge[i].next=-1;
    cnt=0;
}
void addedge(int u,int v,int w){
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
int n,m,b;
int f[maxn];
const int maxf=1e9+10;
struct s_node{
    int id,n_dis;
    s_node(int b,int c):id(b),n_dis(c){}
    bool operator<(const s_node& a)const{
        return n_dis>a.n_dis;
    }
};
int dis[maxn];
bool done[maxn];
priority_queue<s_node> Q;
void dijkstra(int m){
    int s=1;
    memset(dis,0x7f,sizeof(dis));
    memset(done,0,sizeof(done));
    if(f[s]>m) return;
    dis[s]=0;
    Q.push(s_node(s,dis[s]));
    while(!Q.empty()){
        s_node u=Q.top();
        Q.pop();
        if(done[u.id]) continue;
        done[u.id]=true;
        for(int i=head[u.id];~i;i=edge[i].next){
            int y=edge[i].to,w=edge[i].w;
            if(done[y]) continue;
            if(f[y]>m) continue;
            if(dis[y]>w+u.n_dis){
                dis[y]=w+u.n_dis;
                Q.push(s_node(y,dis[y]));
            }
        }
    }
}
bool valid(int m){
    dijkstra(m);
    if(dis[n]>=b) return false;
    return true;
}
int solve(){
    int l=0,r=maxf;
    while(l<r){
        int mid=(l+r)>>1;
        if(valid(mid)) r=mid;
        else l=mid+1;
    }
    return l;
}
int main(){
    scanf("%d%d%d",&n,&m,&b);
    for(int i=1;i<=n;i++) scanf("%d",&f[i]);
    Init();
    for(int i=1;i<=m;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        addedge(a,b,c);
        addedge(b,c,a);
    }
    int ans=solve();
    if(ans==maxf) printf("AFK\n");
    else printf("%d\n",ans);
    return 0;
}

by Snowyyz @ 2020-03-12 21:54:32

建议

int solve(){
    int l=1,r=maxf;
    while(l<r){
        int mid=(l + r) >> 1;
        if(valid(mid)) r=mid - 1, ans = mid;
        else l=mid + 1;
    }
    return l;
}

by Snowyyz @ 2020-03-12 21:54:45

@Sapphire6575737973


by ⚡小林子⚡ @ 2020-03-12 21:55:06

@Sapphire6575737973 这是标题党吗


by iMya_nlgau @ 2020-03-12 21:59:13

@雪花飘飘 试了然而没用,效果一样


by Snowyyz @ 2020-03-12 22:01:23

@Sapphire6575737973 不要return


by Snowyyz @ 2020-03-12 22:02:20

还有要判断开始和终点可不可以走


by iMya_nlgau @ 2020-03-12 22:35:14

我艹找到问题了,我竟然addedge参数写串了


|