| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
陷進了無限的 WA 中...算法該沒有問題的,CEOI '97 的 test data 都過了In Reply To:狂wa。哪位给在下看一下?每一列选且只选一个白点,每一行最多选一个白点,是吗? Posted by:tengshengbo at 2005-08-08 23:37:15 #include <cstdio>
#include <string>
#define ARR 1000
int n, m, a[ARR][ARR], s[ARR], l[ARR], r[ARR];
bool d[ARR];
bool find(int u) {
for (int j = 0, v = a[u][0]; j < s[u]; v = a[u][++j])
if (! d[v]) {
d[v] = true;
if (r[v] == -1 || find(r[v])) {
l[r[v] = u] = v;
return true;
}
}
return false;
}
int main() {
int t; scanf("%d", &t);
while (t--) {
int R=0; scanf("%d%d", &m, &n);
memset(s, 0, sizeof(s));
memset(d, 0, sizeof(d));
for (int i = 0; i < n; i++) {
int x, y; scanf("%d%d", &x, &y); --x, --y;
a[x][s[x]++] = i; a[y][s[y]++] = i;
if (! d[y]) R++, d[y] = true;
if (! d[x]) R++, d[x] = true;
}
int o = 0;
memset(l, -1, sizeof(l));
memset(r, -1, sizeof(r));
for (int i = 0; i < n; i++) {
memset(d, 0, sizeof(d));
if (find(i)) o++;
}
if (o != R) { printf("NO\n"); continue; }
for (int i = 0; i < n; i++)
printf("%d%c", (l[i]!=-1 ? r[i]+1 : a[0][i]), i < n-1 ? ' ' : '\n');
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator