-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path210.cpp
75 lines (72 loc) · 1.38 KB
/
210.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define maxn 500
using namespace std;
struct node{
int v;
node *next;
}*g[maxn];
struct Nnode{
int love,num;
}son[maxn];
int girl[maxn],n,m;
bool use[maxn];
int last[maxn];
void insert(int a,int b){
static node buf[maxn*maxn];
static int top = 0;
node *x = &buf[top++];
x->v =b;x->next = g[a];g[a]=x;
}
bool augment(int x){
node *t = g[x];
while (t!=0){
if (use[t->v]){
use[t->v] = false;
if (last[t->v] == 0 ||
augment(last[t->v])){
last[t->v] = x;
return true;
}
}
t = t->next;
}
return false;
}
int main(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
scanf("%d\n",&n);
for (int i=1;i<=n;++i){
scanf("%d",&son[i].love);
son[i].num = i;
}
for (int i=1;i<=n;++i){int num,tmp;
scanf("%d",&num);
for (int j = 1;j<=num;++j){
scanf(" %d",&tmp);
insert(i,tmp);
}
}
for (int i=1;i<n;++i)
for (int j=i+1;j<=n;++j)
if (son[i].love<son[j].love){
int tmp;
tmp = son[i].num;
son[i].num = son[j].num;
son[j].num = tmp;
tmp = son[i].love;
son[i].love = son[j].love;
son[j].love = tmp;
}
for (int i=1;i<=n;++i){int ans = 0;
memset(use,true,sizeof(use));
if (augment(son[i].num)) ans++;
}
for (int i=1;i<=n;++i)
girl[last[i]] = i;
for (int i=1;i<=n;++i)
printf("%d ",girl[i]);
return 0;
}