/////////////////////////////// _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <tuple>
#include <queue>
#include <ctime>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;
const int N = 50005;
const int inf = 1000 * 1000 * 1000;
const int mod = 998244353;
// mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937 myrand(1337);
int n, m, k;
vector <int> g[N];
bool used[N];
int mt[N];
bool kuhn(int v, int L, int R) {
if (used[v]) return false;
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int to = g[v][i];
if (to < L) continue;
if (to > R) break;
if (mt[to] == -1 || kuhn(mt[to], L, R)) {
mt[to] = v;
return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
int a, b;
cin >> a >> b;
a += m;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 1; i <= m; i++) {
sort(g[i].begin(), g[i].end());
}
int ina = m, inb = n, ind = -1;
while (ina <= inb) {
int mid = (ina + inb) / 2;
for (int i = 1; i <= mid; i++) {
mt[i + m] = -1;
}
int cnt = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
used[j] = false;
}
bool flag = kuhn(i, 1, mid + m);
if (flag) ++cnt;
}
if (cnt == m) {
ind = mid;
inb = mid - 1;
} else {
ina = mid + 1;
}
}
if (ind == -1) {
assert(false);
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
mt[i + m] = -1;
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
used[j] = false;
}
kuhn(i, 1, ind + m);
}
long long answ = n - ind + 1;
for (int i = 1; i <= n; i++) {
if (mt[i + m] == -1) {
answ += n - ind + 1;
continue;
}
int girl = mt[i + m];
while (ind <= n) {
for (int j = 1; j <= m; j++) {
used[j] = false;
}
bool flag = kuhn(girl, i + 1, ind + m);
if (flag) break;
++ind;
}
if (ind == n + 1) break;
answ += n - ind + 1;
}
cout << answ << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1460 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Runtime error |
2 ms |
2900 KB |
Execution killed with signal 6 |
10 |
Runtime error |
3 ms |
2900 KB |
Execution killed with signal 6 |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Runtime error |
2 ms |
2900 KB |
Execution killed with signal 6 |
13 |
Correct |
1 ms |
1608 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
2 ms |
1492 KB |
Output is correct |
18 |
Correct |
1 ms |
1492 KB |
Output is correct |
19 |
Correct |
2 ms |
1492 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Runtime error |
3 ms |
2900 KB |
Execution killed with signal 6 |
22 |
Correct |
1 ms |
1492 KB |
Output is correct |
23 |
Correct |
1 ms |
1492 KB |
Output is correct |
24 |
Correct |
1 ms |
1492 KB |
Output is correct |
25 |
Incorrect |
11 ms |
1620 KB |
Output isn't correct |
26 |
Incorrect |
3 ms |
1492 KB |
Output isn't correct |
27 |
Runtime error |
2 ms |
2900 KB |
Execution killed with signal 6 |
28 |
Correct |
2 ms |
1492 KB |
Output is correct |
29 |
Correct |
3 ms |
1620 KB |
Output is correct |
30 |
Correct |
2 ms |
1492 KB |
Output is correct |
31 |
Correct |
122 ms |
2120 KB |
Output is correct |
32 |
Incorrect |
6 ms |
1616 KB |
Output isn't correct |
33 |
Runtime error |
3 ms |
2900 KB |
Execution killed with signal 6 |
34 |
Correct |
14 ms |
1492 KB |
Output is correct |
35 |
Correct |
62 ms |
2592 KB |
Output is correct |
36 |
Correct |
57 ms |
2560 KB |
Output is correct |
37 |
Correct |
374 ms |
2376 KB |
Output is correct |
38 |
Correct |
17 ms |
2772 KB |
Output is correct |
39 |
Correct |
287 ms |
1808 KB |
Output is correct |
40 |
Runtime error |
7 ms |
3540 KB |
Execution killed with signal 6 |
41 |
Incorrect |
20 ms |
1876 KB |
Output isn't correct |
42 |
Correct |
11 ms |
2132 KB |
Output is correct |
43 |
Correct |
12 ms |
2192 KB |
Output is correct |
44 |
Correct |
27 ms |
2604 KB |
Output is correct |
45 |
Incorrect |
15 ms |
2388 KB |
Output isn't correct |
46 |
Incorrect |
146 ms |
3120 KB |
Output isn't correct |
47 |
Correct |
22 ms |
2992 KB |
Output is correct |
48 |
Correct |
22 ms |
3028 KB |
Output is correct |
49 |
Incorrect |
197 ms |
3356 KB |
Output isn't correct |
50 |
Correct |
450 ms |
1868 KB |
Output is correct |