# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990450 | DAleksa | Marriage questions (IZhO14_marriage) | C++17 | 6 ms | 6808 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, m, k;
vector<int> g[N];
int mt[N];
bool mark[N];
bool dfs(int u) {
if(mark[u]) return false;
mark[u] = true;
for(int v : g[u]) {
if(mt[v] == -1 || dfs(mt[v])) {
mt[v] = u;
return true;
}
}
return false;
}
int max_matching(int l, int r) {
for(int i = 1; i <= m; i++) mt[i] = -1;
int ans = 0;
for(int i = l; i <= r; i++) {
for(int j = l; j <= r; j++) mark[i] = false;
dfs(i);
}
for(int i = 1; i <= m; i++) if(mt[i] != -1) ans++;
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
if(n > 100 || m > 50) assert(false);
for(int i = 1; i <= k; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
}
int ans = 0;
for(int l = 1; l <= n; l++) for(int r = l + m - 1; r <= n; r++) if(max_matching(l, r) == m) ans++;
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |