Pagini recente » Cod sursa (job #1781137) | Cod sursa (job #1532632) | Rating Streche Andrei Claudiu (AndreiStrehe) | Profil AnDrEwBoY | Cod sursa (job #884078)
Cod sursa(job #884078)
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef vector<int>::iterator iter;
const int MAXN = 16400;
vector<int> G[MAXN];
int l[MAXN];
int r[MAXN];
bool vis[MAXN];
int pair_up(int node)
{
if (vis[node])
return 0;
vis[node] = true;
for (iter it = G[node].begin(); it != G[node].end(); ++it) {
if (!r[*it]) {
r[*it] = node;
l[node] = *it;
return 1;
}
}
for (iter it = G[node].begin(); it != G[node].end(); ++it) {
if (pair_up(r[*it])) {
r[*it] = node;
l[node] = *it;
return 1;
}
}
return 0;
}
int deg[MAXN];
int main()
{
freopen("felinare.in", "r", stdin);
freopen("felinare.out", "w", stdout);
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
int x, y;
scanf("%d %d", &x, &y);
y += n;
G[x].push_back(y);
deg[x]++; deg[y]++;
}
for (int poss = 1; poss != 0; ) {
poss = 0;
memset(vis, false, sizeof(vis));
for (int i = 1; i <= n; ++i)
if (!l[i])
poss |= pair_up(i);
}
int coupling = 0;
for (int i = 1; i <= n; ++i)
if (l[i] != 0) ++coupling;
printf("%d\n", 2 * n - coupling);
vector<int> action(n + 1, 3);
for (int i = 1; i <= n; ++i) {
if (l[i] != 0) {
printf("%d\n", 2);
} else {
printf("%d\n", 3);
}
}
return 0;
}