Pagini recente » Cod sursa (job #2388219) | Cod sursa (job #2527073) | Cod sursa (job #39284) | Cod sursa (job #1181169) | Cod sursa (job #883833)
Cod sursa(job #883833)
#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);
for (int i = 1; i <= n; ++i) {
int max_deg = 0;
int action = -1;
if (l[i] != 0 && deg[i] > max_deg) {
max_deg = deg[i];
action = 2;
}
if (action == -1)
printf("%d\n", 3);
else printf("%d\n", action);
}
return 0;
}