Submission #700929

#TimeUsernameProblemLanguageResultExecution timeMemory
700929KiriLL1caMarriage questions (IZhO14_marriage)C++17
88 / 100
1235 ms1876 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define pb push_back #define endl '\n' #define sz(x) (int)((x).size()) #define vec vector #define pw(x) (1ll << x) using namespace std; template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> pii; const int N = 3e4 + 2e3 + 10; vec <int> g[N]; int used[N], mt[N], active[N], us = 0; inline bool kuhn (int v) { if (used[v] == us) return 0; used[v] = us; for (auto &u : g[v]) if (active[u] && !~mt[u]) { mt[u] = v; return 1; } for (auto &u : g[v]) if (active[u] && kuhn(mt[u])) { mt[u] = v; return 1; } return 0; } inline void solve () { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < k; ++i) { int u, v; cin >> u >> v; --u, --v; g[v].pb(u); } fill(mt, mt + N, -1); vec <int> girls; for (int i = 0; i < m; ++i) girls.pb(i); ll ans = 0; for (int l = 0, r = 0; l < n; ++l) { while (r < n) { active[r] = 1; while (sz(girls)) { ++us; int go = girls.back(); if (kuhn(go)) girls.pop_back(); else break; } if (!sz(girls)) break; ++r; } if (!sz(girls)) ans += n - r; if (~mt[l]) { girls.pb(mt[l]); mt[l] = -1; active[l] = 0; } } cout << ans << endl; } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif// LOCAL int t = 1; //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...