#27329: 不知為何SE


vic20050418@gmail.com (Wen Vic)

學校 : 國立臺灣科技大學
編號 : 153262
來源 : [114.136.159.95]
最後登入時間 :
2023-07-29 13:10:41
f260. 愛八卦的同學 | From: [223.136.155.120] | 發表日期 : 2021-09-24 17:06

#include <bits/stdc++.h>

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(0);

int n, k, current1, current2, team_num;

int group[1000000000] = { 0 };

while (cin >> n >> k) {

team_num = 1;

for (int i = 0; i < k; i++) {

cin >> current1 >> current2;

if (group[current1] == 0) {

if (group[current2] == 0) {

group[current1] = team_num;

group[current2] = team_num;

team_num++;

}

else {

group[current1] = group[current2];

}

}

else {

if (group[current2] == 0) {

group[current2] = group[current1];

}

}

}

cout << team_num - 1 << '\n';

memset(group, 0, n * 4);

}

}

 
#27331: Re:不知為何SE


linlincaleb@gmail.com (臨末之頌)

學校 : 新北市立板橋高級中學
編號 : 132772
來源 : [203.64.161.123]
最後登入時間 :
2024-07-29 10:02:49
f260. 愛八卦的同學 | From: [111.248.103.86] | 發表日期 : 2021-09-24 18:43

#include <bits/stdc++.h>

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(0);

int n, k, current1, current2, team_num;

int group[1000000000] = { 0 };

while (cin >> n >> k) {

team_num = 1;

for (int i = 0; i < k; i++) {

cin >> current1 >> current2;

if (group[current1] == 0) {

if (group[current2] == 0) {

group[current1] = team_num;

group[current2] = team_num;

team_num++;

}

else {

group[current1] = group[current2];

}

}

else {

if (group[current2] == 0) {

group[current2] = group[current1];

}

}

}

cout << team_num - 1 << '\n';

memset(group, 0, n * 4);

}

}

應該是陣列太大了

 
ZeroJudge Forum