Pagini recente » Cod sursa (job #264433) | Cod sursa (job #1783321) | Cod sursa (job #1290489) | Cod sursa (job #2038914) | Cod sursa (job #1956892)
#include <bits/stdc++.h>
#define maxN 8193
FILE *fin = freopen("felinare.in", "r", stdin);
FILE *fout = freopen("felinare.out", "w", stdout);
using namespace std;
int N, M;
int card;
int Left[maxN], Right[maxN];
bool suppLeft[maxN], suppRight[maxN];
bitset <maxN> used;
vector <int> G[maxN];
bool PairUp(int node){
if(used.test(node)) return 0;
used.set(node);
for(int son : G[node])
if(!Left[son]){
suppLeft[node] = true;
++ card;
Right[node] = son;
Left[son] = node;
return 1;
}
for(int son : G[node])
if(PairUp(Left[node])){
suppLeft[node] = true;
Right[node] = son;
Left[son] = node;
return 1;
}
return 0;
}
void Support(int node){
for(int son : G[node])
if(!suppRight[son]){
suppRight[son] = true;
suppLeft[Left[son]] = false;
Support(Left[son]);
}
}
void MvC(){
bool change;
do{
change = false;
used.reset();
for(int i = 1; i <= N; ++ i)
if(!suppLeft[i])
change |= PairUp(i);
}while(change);
for(int i = 1; i <= N; ++ i)
if(!suppLeft[i])
Support(i);
}
int main(){
scanf("%d %d", &N, &M);
for(int i = 1; i <= M; ++ i){
int x, y;
scanf("%d %d", &x, &y);
G[x].push_back(y);
//G[y].push_back(x);
}
MvC();
printf("%d\n", 2*N - card);
for(int i = 1; i <= N; i++) {
int val = 3;
if(suppLeft[i]){
val--;
}
if(suppRight[i]){
val -= 2;
}
printf("%d\n", val);
}
return 0;
}