作者AceKiller (皇牌杀手)
看板C_and_CPP
标题[ACM ] 315 RE
时间Fri Apr 17 22:54:44 2009
这是我的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
1F:推 ljwu:int set[n+1] 动态宣告? 应该不行吧 改用动态配置试试看@@ 04/17 23:27
2F:推 ledia:如果不行应该会是 CE 而非 RE 04/18 00:48
3F:推 ledia:问题在你预设每个编号都只有一位数 04/18 00:57
4F:→ ledia: n 最大是可能到 99 的 04/18 00:57
5F:→ AceKiller:感谢楼上 AC了 04/18 11:07