L3-022 地铁一日游 (30 分) 这段代码为何段错误,离谱

img

img

img

img


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int Max=1e6+5;
const int INF=1e9+5;
int n,m,k;
struct node{
    int to;
    ll key;
};
vector<node>mp[Max];
vector<int>dp[Max];
int hx;
void dfs(int fa,int x,int num){
//    cout<<fa<<' '<<x<<endl;
//    if(mp[x].size()==1&&fa!=-1){
//        dp[ret].pb(x);
//        return ;
//    }
    for(int i=0;i<mp[x].size();i++){
        int v=mp[x][i].to;
        if(fa==v) continue;
//        if(num/k!=(num+mp[x][i].key)/k){
//            dp[hx].pb(x);
//            dfs(x,v,0);
//        }
//        else{
//            dfs(x,mp[x][i].to,num+mp[x][i].key);
//        }
    }
}
int main(){
    cin>>n>>m>>k;
    for(int i=0;i<m;i++){
        int pre;cin>>pre;
        int w,x;
        while(cin>>w>>x){
            mp[pre].pb({x,w});
            mp[x].pb({pre,w});
            pre=x;
            if(getchar()=='\n') break;
        }
    }
//    dfs(-1,1,0);
    int q;
    cin>>q;
    while(q--){
        cin>>hx;
//        dp[hx].insert(hx);
        dfs(-1,hx,0);
        dp[hx].pb(hx);
        set<int>temp;vector<int>ans;
        for(int i=0;i<dp[hx].size();i++) temp.insert(dp[hx][i]);
        for(set<int>::iterator it=temp.begin();it!=temp.end();it++){
            int hy=*it;
            ans.pb(hy);
        }
        for(int i=0;i<ans.size()-1;i++) cout<<ans[i]<<' ';cout<<ans[ans.size()-1]<<endl;
    }
}