Submission #990449

#TimeUsernameProblemLanguageResultExecution timeMemory
990449DAleksaMarriage questions (IZhO14_marriage)C++17
32 / 100
1579 ms5200 KiB
#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; 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 timeMemoryGrader output
Fetching results...