瘾ิۣۖิۣۖิۣۖิꦿ 2022-04-20 20:56 采纳率: 100%
浏览 65
已结题

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;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月28日
    • 创建了问题 4月20日

    悬赏问题

    • ¥15 无法输出helloworld
    • ¥15 高通uboot 打印ubi init err 22
    • ¥20 PDF元数据中的XMP媒体管理属性
    • ¥15 R语言中lasso回归报错
    • ¥15 网站突然不能访问了,上午还好好的
    • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
    • ¥15 semrush,SEO,内嵌网站,api
    • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
    • ¥15 振荡电路,ADS仿真
    • ¥15 关于#c语言#的问题,请各位专家解答!