[ACM ] 315 RE
這是我的code 跑測試沒問題 但是一上傳就吃RE 找了很久都找不出原因 囧
請問有強者可以幫我指點一下嗎 先謝了~
#include<iostream>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
#define MAX 101
using namespace std;
int g[MAX][MAX];
void make_set(int *set, int n)
{
for(int i = 1; i <= n; i++)
set[i] = i;
}
void union_set(int *set, int n, int x, int y)
{
int min = (x < y)? x: y;
int max = (x > y)? x: y;
for(int i = 1; i <= n; i++)
if(set[i] == max)
set[i] = min;
}
int cc(int n, int ex)
{
int set[n+1], i, j;
vector<int> count;
vector<int>::iterator it;
make_set(set, n);
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
if(i != ex && j != ex && g[i][j] == 1 && set[i] != set[j])
union_set(set, n, set[i], set[j]);
for(i = 1; i <= n; i++)
if(i != ex)
count.push_back(set[i]);
sort(count.begin(), count.end());
it = unique(count.begin(), count.end());
count.resize(it - count.begin());
return count.size();
}
int main()
{
int n, i, head, orig, critical;
string str;
while(cin >> n && n != 0) {
memset(g, 0, sizeof(g));
while(getline(cin, str)) {
if(str == "0")
break;
head = str[0]-'0';
for(i = 2; i < str.length(); i+=2) {
g[head][str[i]-'0'] = 1;
g[str[i]-'0'][head] = 1;
}
}
orig = cc(n, 0);
critical = 0;
for(i = 1; i <= n; i++)
if(cc(n, i) > orig)
critical++;
cout << critical << endl;
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.138.71.223
推
04/17 23:27, , 1F
04/17 23:27, 1F
推
04/18 00:48, , 2F
04/18 00:48, 2F
推
04/18 00:57, , 3F
04/18 00:57, 3F
→
04/18 00:57, , 4F
04/18 00:57, 4F
→
04/18 11:07, , 5F
04/18 11:07, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章