程序为何异常跳出
  • 板块灌水区
  • 楼主Qtl123
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/1/10 21:31
  • 上次更新2024/1/11 12:57:34
查看原帖
程序为何异常跳出
1018534
Qtl123楼主2024/1/10 21:31
#include<bits/stdc++.h>
using namespace std;
int n,m,p,a[100000];
int x,y;
int mid(int k){
    return k==a[k]?k:a[k]=mid(a[k]);
}
void abb(int x1,int y1){
    int xxx=mid(x1),yyy=mid(y1);
    if(xxx==yyy){
        return;
    }
    a[xxx]=yyy;
}
int main(){
    cin>>m>>n;
    for(int i=1;i<=n;i++){
        a[i]=i;
    }
    int d,d1;
    for(int i=1;i<=m;i++){
        cin>>d>>d1;
        abb(d,d1);
    }
    cin>>p;
    for(int i=1;i<=p;i++){
        cin>>x>>y;
        if(mid(x)==mid(y)){
            cout<<"Yes";
        }else{
            cout<<"No";
        }
        cout<<endl;
    }
    while(1);
}

为什么用CodeBlocks的时候会一场跳出 洛谷上测也只会输出两个NO

//这是测试点
101 11300
34 152
78 632
1230 1231
675 345
121 367
672 346
231 89
3 67
12 89
31 999
250 542
732 351
1147 547
457 470
48 74
1123 543
429 1
1 34
547 923
139 1004
1001 1
219 328
549 804
10 20
30 64
12 78
345 23
97 12
54 82
1110 1134
1234 234
654 425
123 243
638 562
274 815
934 762
1061 912
231 132
29 30
713 90
13 90
342 510
90 345
1230 472
571 942
666 888
603 124
345 310
372 1045
1213 46
2 34
5 39
67 76
8 21
59 283
518 214
692 183
192 102
12 64
9 46
64 97
356 9
38 73
36 8
1203 69
9 1
234 1
759 2
3 590
54 72
40 291
720 375
95 10
2 87
63 21
596 1048
28 34
34 21
683 24
103 19
69 202
10 38
34 29
2 1043
137 2
824 57
82 385
947 34
102 53
491 253
123 45
57 910
730 1002
395
1230 218
2 491
591 424
148 279
2 340
6 39
4 185
10
2 401
12 504
1 46
491 79
2 1230
9 1001
2 340
12 49
29 739
28 152

2024/1/10 21:31
加载中...