Submission #990443

#TimeUsernameProblemLanguageResultExecution timeMemory
990443DAleksaMarriage questions (IZhO14_marriage)C++17
32 / 100
1577 ms4232 KiB
#include <bits/stdc++.h> using namespace std; 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; if(dfs(i)) ans++; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; 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; r <= n; r++) if(max_matching(l, r) == m) ans++; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...