Pagini recente » Cod sursa (job #57477) | Cod sursa (job #65489) | Cod sursa (job #573771) | Cod sursa (job #775069) | Cod sursa (job #2660421)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
ifstream f("paznici.in");
ofstream g("paznici.out");
const int maxn = 30;
vector <int> nod[maxn];
string s;
int n, m, i, j, cup;
int viz[maxn], ok;
int r[maxn], l[maxn];
int a1[maxn], a2[maxn];
bool match(int x) {
if(viz[x] != 0) { return false; }
viz[x] = 1;
for(auto u : nod[x]) {
if(l[u] == false) {
l[u] = x;
r[x] = u;
return true;
}
}
for(auto u : nod[x]) {
if(match(l[u]) == true) {
l[u] = x;
r[x] = u;
return true;
}
}
return false;
}
void dfs(int x) {
viz[x] = 1;
a1[x] = 0;
for(auto u : nod[x]) {
if(viz[r[u]] == 0) {
a2[u] = true;
dfs(u);
}
}
}
int main()
{
f >> n >> m;
for(i = 1; i <= n; i ++) {
f >> s;
for(j = 0; j < m; j ++) {
if(s[j] == '1') {
nod[i].push_back(j + 1);
}
}
}
do {
ok = false;
memset(viz, 0, sizeof(viz));
for(i = 1; i <= n; i ++) {
if(l[i] == 0 && match(i) == true) {
++cup;
ok = true;
}
}
} while(ok == true);
for(i = 1; i <= n; i ++) {
if(l[i] != 0) {
a1[i] = true;
viz[i] = true;
}
}
for(i = 1; i <= n; i ++) {
if(l[i] == 0) {
dfs(i);
}
}
for(i = 1; i <= n; i ++) {
if(a1[i] == true) {
g << (char)(i + 'A' + 1);
}
}
for(i = 1; i <= n; i ++) {
if(a2[i] == true) {
g << (char)(i + 'a' + 1);
}
}
f.close(); g.close();
return 0;
}