効果の対象に
もしN学生からの番号(SIM-1 {N} \ \ 0)\、各行は、次の番号を表し\(iは\)学生とそれらの対応する番号の数との間の学生「ロマンチック」関係の\(S_I \を)、あなたは(何を一人一人との関係がある)で、「ロマンチックな関係」に含まれる人々の最大数を見つけることができます
サンプル入力
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
サンプル出力
5
2
問題解決のためのアイデア
地図上の最初言っても過言ではありません
ロード......
サンプルコード
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int e[maxn][maxn];
int match[maxn];
bool book[maxn];
int n;
bool dfs(int u)
{
for (int i = 0; i < n; i++)
{
if (book[i] == false && e[u][i] == 1)
{
book[i] = true;
if (match[i] == 0 || dfs(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
}
int main()
{
while (~scanf("%d", &n))
{
int sum = 0;
memset(e, 0, sizeof(e));
memset(match, 0, sizeof(match));
for (int i = 0; i < n; i++)
{
int fr, m;
char a,b,c,f;
scanf("%d%c%c",&fr,&a,&f);
scanf("%c%d%c",&b,&m,&c);
// cout << f << " " << m << endl;
for (int j = 0; j < m; j++)
{
int to;
scanf("%d", &to);
e[fr][to] = 1;
}
}
for (int i = 0; i < n; i++)
{
memset(book, false, sizeof(book));
if (dfs(i))
sum++;
}
printf("%d\n", n - sum / 2);
}
return 0;
}