A* 60pts WA求助
  • 板块P2829 大逃离
  • 楼主Bwahoji
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/13 16:58
  • 上次更新2024/3/13 19:18:58
查看原帖
A* 60pts WA求助
344756
Bwahoji楼主2024/3/13 16:58

代码如下:

#include<bits/stdc++.h>
using namespace std;
struct point{
    int t,v;
};
const int N=6e3;
int h[N];
struct node1{
    int v,w;
    bool operator < (const node1 &x)const{ return v>x.v; }
};
struct node2{
    int v,w;
    bool operator < (const node2 &x)const{ return w+h[v]>x.w+h[x.v]; }
};
priority_queue<node1>Q;
priority_queue<node2>Q2;
node1 nw1;
node2 nw2;

int n,m,k;
vector<point>q[N];
bool vis1[N];
int vis2[N];
int degree[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1,u,v,w;i<=m;i++){
        cin>>u>>v>>w;
        q[u].push_back((point){v,w});
        q[v].push_back((point){u,w});
        degree[u]++,degree[v]++;
    }
    degree[1]=INT_MAX;
    degree[n]=INT_MAX;
    memset(h,0x3f,sizeof h);
    Q.push({n,0});
    while(!Q.empty()){
        nw1=Q.top();
        Q.pop();
        if(vis1[nw1.v])continue;
        vis1[nw1.v]=1;
        h[nw1.v]=nw1.w;
        for(auto v:q[nw1.v]){
            if(degree[v.t]>=k)
                Q.push((node1){v.t,v.v+nw1.w});
        }
    }
    Q2.push({1,0});
    while(!Q2.empty()){
        nw2=Q2.top();
        Q2.pop();
        vis2[nw2.v]++;
        if(nw2.v==n&&vis2[nw2.v]==2){
            cout<<nw2.w;
            return 0;
        }
        if(vis2[nw2.v]>2)continue;
        for(auto v:q[nw2.v]){
            if(degree[v.t]>=k)
                Q2.push((node2){v.t,v.v+nw2.w});
        }
    }
    cout<<-1;

    return 0;
}
2024/3/13 16:58
加载中...