奇怪的报错
  • 板块P2814 家谱
  • 楼主jianamisabina
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/6/27 22:17
  • 上次更新2023/11/3 12:16:58
查看原帖
奇怪的报错
775991
jianamisabina楼主2023/6/27 22:17

这题我用并查集 + map做,全RE。

调试了一下,父子关系似乎没错(?)

报错信息是double free or corruption (out)

bdfs无果,求调

#include <iostream>
#include <map>
#define N 500100
using namespace std;

map <string,string> p;
char op;
string name,dad;

string found(string k){
    if(k == p[k]) return k;
    else p[k] = found(p[k]);
}

void print(string str){
    int len = str.size();
    for(int i = 0;i < len;i ++){
        cout << str[i];
    }
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    while(cin >> op){
        if(op == '$') break;
        cin >> name;
        if(p[name] == "") p[name] = name;
        if(op == '#'){
            dad = name;
        }
        if(op == '+'){
            p[name] = dad;
        }
        if(op == '?'){
            print(name);cout << ' ';
            print(found(name)); cout << '\n';
        }
    }
    return 0;
}
2023/6/27 22:17
加载中...