/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
#include <functional>
using namespace std;
using LL = long long;
const int N = 1e3 + 5;
const LL mod = 998244353, inf = 1e18;
vector<int> dx = { 1, 0, -1, 0, 1, -1, 1, -1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, 1, -1 };
void solve() {
int n, m, k; cin >> n >> m >> k;
vector<vector<int>> gp(n + m);
for (int i = 0; i < k; ++i) {
int u, v; cin >> u >> v;
u += m;
gp[--u].push_back(--v);
gp[v].push_back(u);
}
int ans = 0;
vector<int> mt(n + m, -1);
vector<bool> vis(n + m);
function<bool(int, int, int)> kuhn = [&](int u, int l, int r) {
if (vis[u]) return 0;
vis[u] = 1;
for (int& v : gp[u]) {
if (v < l || v > r) continue;
if (mt[v] == -1 || kuhn(mt[v], l, r)) {
mt[v] = u;
return 1;
}
}
return 0;
};
int l = m - 5, r = n, idx = -1;
while (l <= r) {
int mid = (l + r) / 2;
mt = vector<int>(n + m, -1);
int cnt = 0;
for (int i = 0; i < m; ++i) {
vis = vector<bool>(n + m);
cnt += kuhn(i, 0, m + mid);
}
if(cnt == m){
r = mid;
idx = mid;
}
else {
l = mid;
}
}
if (idx == -1) {
cout << "0\n";
return;
}
ans += n - idx;
mt = vector<int>(n + m, -1);
for (int i = 0; i < m; ++i) {
vis = vector<bool>(n + m);
kuhn(i, m, idx + m);
}
for (int i = 0; i < n; ++i) {
if (mt[i + m] == -1) {
ans += n - idx;
continue;
}
int u = mt[i + m];
while (idx < n) {
vis = vector<bool>(n + m);
if (kuhn(u, i + 1 + m, idx + m)) break;
++idx;
}
if (idx == n) break;
ans += n - idx;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t; cin >> t; while (t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1557 ms |
212 KB |
Time limit exceeded |
2 |
Execution timed out |
1572 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
1561 ms |
212 KB |
Time limit exceeded |
4 |
Execution timed out |
1565 ms |
212 KB |
Time limit exceeded |
5 |
Execution timed out |
1574 ms |
212 KB |
Time limit exceeded |
6 |
Execution timed out |
1578 ms |
212 KB |
Time limit exceeded |
7 |
Execution timed out |
1572 ms |
212 KB |
Time limit exceeded |
8 |
Execution timed out |
1576 ms |
212 KB |
Time limit exceeded |
9 |
Execution timed out |
1578 ms |
212 KB |
Time limit exceeded |
10 |
Execution timed out |
1563 ms |
212 KB |
Time limit exceeded |
11 |
Execution timed out |
1577 ms |
212 KB |
Time limit exceeded |
12 |
Execution timed out |
1588 ms |
212 KB |
Time limit exceeded |
13 |
Execution timed out |
1538 ms |
212 KB |
Time limit exceeded |
14 |
Execution timed out |
1569 ms |
212 KB |
Time limit exceeded |
15 |
Execution timed out |
1585 ms |
212 KB |
Time limit exceeded |
16 |
Execution timed out |
1571 ms |
212 KB |
Time limit exceeded |
17 |
Execution timed out |
1573 ms |
212 KB |
Time limit exceeded |
18 |
Execution timed out |
1577 ms |
212 KB |
Time limit exceeded |
19 |
Execution timed out |
1588 ms |
340 KB |
Time limit exceeded |
20 |
Execution timed out |
1556 ms |
212 KB |
Time limit exceeded |
21 |
Execution timed out |
1538 ms |
212 KB |
Time limit exceeded |
22 |
Execution timed out |
1557 ms |
212 KB |
Time limit exceeded |
23 |
Execution timed out |
1572 ms |
212 KB |
Time limit exceeded |
24 |
Execution timed out |
1554 ms |
212 KB |
Time limit exceeded |
25 |
Execution timed out |
1577 ms |
468 KB |
Time limit exceeded |
26 |
Execution timed out |
1574 ms |
340 KB |
Time limit exceeded |
27 |
Execution timed out |
1565 ms |
340 KB |
Time limit exceeded |
28 |
Execution timed out |
1569 ms |
340 KB |
Time limit exceeded |
29 |
Execution timed out |
1573 ms |
340 KB |
Time limit exceeded |
30 |
Execution timed out |
1576 ms |
340 KB |
Time limit exceeded |
31 |
Execution timed out |
1581 ms |
980 KB |
Time limit exceeded |
32 |
Execution timed out |
1574 ms |
340 KB |
Time limit exceeded |
33 |
Execution timed out |
1570 ms |
340 KB |
Time limit exceeded |
34 |
Execution timed out |
1583 ms |
340 KB |
Time limit exceeded |
35 |
Execution timed out |
1563 ms |
1364 KB |
Time limit exceeded |
36 |
Execution timed out |
1573 ms |
1364 KB |
Time limit exceeded |
37 |
Execution timed out |
1563 ms |
1172 KB |
Time limit exceeded |
38 |
Execution timed out |
1567 ms |
1620 KB |
Time limit exceeded |
39 |
Execution timed out |
1564 ms |
1088 KB |
Time limit exceeded |
40 |
Execution timed out |
1555 ms |
980 KB |
Time limit exceeded |
41 |
Execution timed out |
1558 ms |
1108 KB |
Time limit exceeded |
42 |
Execution timed out |
1533 ms |
1364 KB |
Time limit exceeded |
43 |
Execution timed out |
1542 ms |
1496 KB |
Time limit exceeded |
44 |
Execution timed out |
1574 ms |
1984 KB |
Time limit exceeded |
45 |
Execution timed out |
1598 ms |
2240 KB |
Time limit exceeded |
46 |
Execution timed out |
1570 ms |
2900 KB |
Time limit exceeded |
47 |
Execution timed out |
1564 ms |
2828 KB |
Time limit exceeded |
48 |
Execution timed out |
1578 ms |
2832 KB |
Time limit exceeded |
49 |
Execution timed out |
1582 ms |
3020 KB |
Time limit exceeded |
50 |
Execution timed out |
1564 ms |
1792 KB |
Time limit exceeded |