# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96055 | 2019-02-05T13:53:01 Z | Kastanda | Marriage questions (IZhO14_marriage) | C++11 | 851 ms | 1952 KB |
#include<bits/stdc++.h> #define pb push_back using namespace std; const int MAXN = 34004; int n, m, k, ts, l, r, MC[MAXN], M[MAXN]; vector < int > Adj[MAXN]; queue < int > qu; int DFS(int v) { if (M[v] == ts) return 0; M[v] = ts; for (int i = 0; i < (int)Adj[v].size(); i++) if (l <= Adj[v][i] && Adj[v][i] <= r) if (MC[Adj[v][i]] == -1 || DFS(MC[Adj[v][i]])) return MC[Adj[v][i]] = v, 1; return 0; } inline int Match() { while (qu.size()) { int v = qu.front(); qu.pop(); ts ++; if (!DFS(v)) return qu.push(v), 1; } return 1; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; i++) { int v, u; scanf("%d%d", &v, &u); Adj[u].pb(v); } int tot = 0; memset(MC, -1, sizeof(MC)); for (int i = 1; i <= m; i++) qu.push(i); for (l = 1; l <= n; l ++) { r = max(r, l); Match(); while (r < n && qu.size()) r ++, Match(); if (qu.size()) break; tot += n - r + 1; if (MC[l] != -1) qu.push(MC[l]), MC[l] = -1; } return !printf("%d\n", tot); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1272 KB | Output is correct |
4 | Correct | 3 ms | 1272 KB | Output is correct |
5 | Correct | 2 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1272 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 2 ms | 1272 KB | Output is correct |
9 | Correct | 3 ms | 1272 KB | Output is correct |
10 | Correct | 2 ms | 1272 KB | Output is correct |
11 | Correct | 3 ms | 1272 KB | Output is correct |
12 | Correct | 3 ms | 1272 KB | Output is correct |
13 | Correct | 3 ms | 1272 KB | Output is correct |
14 | Correct | 3 ms | 1272 KB | Output is correct |
15 | Correct | 3 ms | 1272 KB | Output is correct |
16 | Correct | 2 ms | 1272 KB | Output is correct |
17 | Correct | 2 ms | 1276 KB | Output is correct |
18 | Correct | 3 ms | 1272 KB | Output is correct |
19 | Correct | 4 ms | 1272 KB | Output is correct |
20 | Correct | 3 ms | 1272 KB | Output is correct |
21 | Correct | 3 ms | 1272 KB | Output is correct |
22 | Correct | 3 ms | 1272 KB | Output is correct |
23 | Correct | 3 ms | 1272 KB | Output is correct |
24 | Correct | 3 ms | 1272 KB | Output is correct |
25 | Correct | 39 ms | 1272 KB | Output is correct |
26 | Correct | 7 ms | 1272 KB | Output is correct |
27 | Correct | 3 ms | 1272 KB | Output is correct |
28 | Correct | 3 ms | 1400 KB | Output is correct |
29 | Correct | 4 ms | 1272 KB | Output is correct |
30 | Correct | 4 ms | 1272 KB | Output is correct |
31 | Correct | 281 ms | 1656 KB | Output is correct |
32 | Correct | 12 ms | 1272 KB | Output is correct |
33 | Correct | 3 ms | 1272 KB | Output is correct |
34 | Correct | 5 ms | 1272 KB | Output is correct |
35 | Correct | 107 ms | 1784 KB | Output is correct |
36 | Correct | 78 ms | 1784 KB | Output is correct |
37 | Correct | 851 ms | 1764 KB | Output is correct |
38 | Correct | 20 ms | 1756 KB | Output is correct |
39 | Correct | 97 ms | 1400 KB | Output is correct |
40 | Correct | 6 ms | 1400 KB | Output is correct |
41 | Correct | 8 ms | 1400 KB | Output is correct |
42 | Correct | 8 ms | 1400 KB | Output is correct |
43 | Correct | 12 ms | 1528 KB | Output is correct |
44 | Correct | 19 ms | 1832 KB | Output is correct |
45 | Correct | 11 ms | 1532 KB | Output is correct |
46 | Correct | 51 ms | 1952 KB | Output is correct |
47 | Correct | 23 ms | 1784 KB | Output is correct |
48 | Correct | 21 ms | 1784 KB | Output is correct |
49 | Correct | 98 ms | 1932 KB | Output is correct |
50 | Correct | 232 ms | 1488 KB | Output is correct |