Pagini recente » Cod sursa (job #1834186) | Cod sursa (job #2832148) | Cod sursa (job #233929) | Cod sursa (job #3149414) | Cod sursa (job #2887306)
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream fin("felinare.in");
ofstream fout("felinare.out");
int n, m, x, y, st[8200], d[8200], ans;
vector<int> G[8200];
bitset<8200> v;
bool cuplaj(int nod) {
if(v[nod]) {
return false;
}
v[nod] = true;
for(auto i : G[nod]) {
if(d[i] == 0) {
st[nod] = 1;
d[i] = nod;
return true;
}
}
for(auto i : G[nod]) {
if(cuplaj(d[i])) {
st[nod] = 1;
d[i] = nod;
return true;
}
}
return false;
}
int main() {
fin >> n >> m;
for(int i = 1; i <= m; i++) {
fin >> x >> y;
G[x].push_back(y);
}
fin.close();
bool gasit = true;
while(gasit) {
gasit = false;
v.reset();
for(int i = 1; i <= n; i++) {
if(st[i] == 0) {
gasit |= cuplaj(i);
}
}
}
for(int i = 1; i <= n; i++) {
ans += (st[i] > 0);
}
fout << 2 * n - ans << "\n";
for(int i = 1; i <= n; i++) {
fout << (st[i] ^ 3) << "\n";
}
return 0;
}