- 家族
- 2014-12-04 11:01:33 @
测试数据#6是有什么特别的地方吗?我只有那个样例错
代码如下:
#include<iostream>
#include<set>
using namespace std;
int main() {
int people, relative, sample;
cin >> people >> relative >> sample;
int setnum[people+5];
int group[people+5];
for (int i = 0; i <= people+1; i++) {
setnum[i] = 0;
group[i] = 0;
}
int a, b;
for (int r = 1; r <= relative; r++) {
cin >> a >> b;
if (setnum[a] == 0&&setnum[b] == 0) {
for (int i = 1; i <= people+1; i++) {
if (group[i] == 0) {
group[i] = 1;
setnum[a] = setnum[b] = i;
break;
}
}
}
else if (setnum[a] != 0&&setnum[b] == 0) {
setnum[b] = setnum[a];
}
else if (setnum[b] != 0&&setnum[a] == 0) {
setnum[a] = setnum[b];
}
else if (setnum[a] != 0&&setnum[b] == setnum[a]) {
} else {
int temp1, temp2;
temp1 = (setnum[a] < setnum[b])?setnum[a]:setnum[b];
temp2 = (setnum[a] > setnum[b])?setnum[a]:setnum[b];
for (int t = 1; t <= people; t++) {
if (setnum[t] == temp2) {
setnum[t] = temp1;
}
}
group[temp2] = 0;
}
}
int c, d;
for (int s = 1; s <= sample; ++s) {
cin >> c >> d;
if (setnum[c] != 0&&setnum[c] == setnum[d]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
2 条评论
-
残阳~·鲜血如虹 LV 7 @ 2016-03-07 17:48:07
// input code here
-
2015-09-09 13:11:32@
我也是,一直都是这组数据出错
- 1