Submission #700945

#TimeUsernameProblemLanguageResultExecution timeMemory
700945KiriLL1caMarriage questions (IZhO14_marriage)C++17
100 / 100
776 ms2548 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], us = 1; inline bool kuhn (int v, int l, int r) { if (used[v] == us) return 0; used[v] = us; for (auto &u : g[v]) if (l <= u && u <= r && (!~mt[u] || kuhn(mt[u], l, r))) { 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) { while (sz(girls)) { ++us; int go = girls.back(); if (kuhn(go, l, r)) girls.pop_back(); else break; } if (!sz(girls)) break; ++r; } if (sz(girls)) break; ans += n - r; if (~mt[l]) { girls.pb(mt[l]); mt[l] = -1; } } 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...