Pagini recente » Cod sursa (job #1138892) | Rating Pop-Coman Florin (Florinellu) | Profil vicorico | Cod sursa (job #2703679) | Cod sursa (job #1961831)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("felinare.in");
ofstream g("felinare.out");
const int nmax = 9000;
int x, y, n, m, cnt, K, i;
vector <int> ls[nmax];
int viz[nmax], st[nmax], dr[nmax];
bool stinsst[nmax], stinsdr[nmax];
bool pereche(int x) {
if (viz[x]==K) return 0;
int l = ls[x].size(), i, y;
viz[x] = K;
for (i = 0; i < l; i++) {
y = ls[x][i];
if (dr[y] == 0 || pereche(dr[y])) {
st[x] = y;
dr[y] = x;
return 1;
}
}
return 0;
}
void aprinde(int x) {
int l = ls[x].size(), i, y;
for (i = 0; i < l; i++) {
y = ls[x][i];
if (stinsdr[y] == 0) {
stinsst[dr[y]] = 0;
stinsdr[y] = 1;
aprinde(dr[y]);
}
}
}
int main() {
f >> n >> m;
for (i = 1; i <= m; i++) {
f >> x >> y;
ls[x].push_back(y);
}
for (i = 1; i <= n; i++) {
K = i;
cnt += pereche(i);
}
g << 2*n - cnt << '\n';
for (i = 1; i <= n; i++)
stinsst[i] = (st[i] != 0);
for (i = 1; i <= n; i++)
if (st[i] == 0)
aprinde(i);
for (i = 1; i <= n; i++) {
cnt = 0;
if (stinsst[i]==0) cnt++;
if (stinsdr[i]==0) cnt+=2;
g << cnt << '\n';
}
return 0;
}