# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91408 | 2018-12-27T11:41:29 Z | mirbek01 | Marriage questions (IZhO14_marriage) | C++11 | 851 ms | 5424 KB |
# include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, m, k, mt[N], used[N], ans, L, R, pt = 1; vector <int> g[N], mr; bool dfs(int v){ if(used[v]) return 0; used[v] = 1; for(int to : g[v]){ if(to < L) break; if(to <= n && to > R) continue; if(mt[to] == -1 || dfs(mt[to])){ mt[to] = v; mt[v] = to; return true; } } return false; } bool check(){ while(!mr.empty()){ int v = mr.back(); if(mt[v] == -1){ memset(used, 0, sizeof(used)); if(!dfs(v)) return false; } mr.pop_back(); } return mr.empty(); } int main(){ scanf("%d %d %d", &n, &m, &k); for(int i = 1; i <= k; i ++){ int a, b; scanf("%d %d", &a, &b); g[a].push_back(b + n); g[b + n].push_back(a); } for(int i = n + 1; i <= n + m; i ++) sort(g[i].rbegin(), g[i].rend()); memset(mt, -1, sizeof(mt)); for(int i = n + 1; i <= n + m; i ++) mr.push_back(i); for(int i = 1; i <= n; i ++){ L = i, R = pt; while(pt <= n && !check()) pt ++, R = pt; ans += n - pt + 1; if(mt[L] != -1){ mt[mt[L]] = -1; mr.push_back(mt[L]); } } printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3448 KB | Output is correct |
2 | Correct | 4 ms | 3448 KB | Output is correct |
3 | Correct | 4 ms | 3480 KB | Output is correct |
4 | Correct | 4 ms | 3480 KB | Output is correct |
5 | Correct | 4 ms | 3544 KB | Output is correct |
6 | Correct | 4 ms | 3576 KB | Output is correct |
7 | Correct | 5 ms | 3624 KB | Output is correct |
8 | Correct | 4 ms | 3664 KB | Output is correct |
9 | Correct | 4 ms | 3692 KB | Output is correct |
10 | Correct | 4 ms | 3692 KB | Output is correct |
11 | Correct | 4 ms | 3692 KB | Output is correct |
12 | Correct | 4 ms | 3708 KB | Output is correct |
13 | Correct | 4 ms | 3708 KB | Output is correct |
14 | Correct | 4 ms | 3708 KB | Output is correct |
15 | Correct | 4 ms | 3708 KB | Output is correct |
16 | Correct | 4 ms | 3732 KB | Output is correct |
17 | Correct | 4 ms | 3732 KB | Output is correct |
18 | Correct | 4 ms | 3732 KB | Output is correct |
19 | Correct | 8 ms | 3732 KB | Output is correct |
20 | Correct | 8 ms | 3732 KB | Output is correct |
21 | Correct | 6 ms | 3732 KB | Output is correct |
22 | Correct | 7 ms | 3732 KB | Output is correct |
23 | Correct | 8 ms | 3732 KB | Output is correct |
24 | Correct | 8 ms | 3836 KB | Output is correct |
25 | Correct | 33 ms | 3836 KB | Output is correct |
26 | Correct | 24 ms | 3836 KB | Output is correct |
27 | Correct | 15 ms | 3836 KB | Output is correct |
28 | Correct | 15 ms | 3836 KB | Output is correct |
29 | Correct | 16 ms | 3836 KB | Output is correct |
30 | Correct | 16 ms | 3836 KB | Output is correct |
31 | Correct | 138 ms | 4348 KB | Output is correct |
32 | Correct | 35 ms | 4348 KB | Output is correct |
33 | Correct | 23 ms | 4348 KB | Output is correct |
34 | Correct | 34 ms | 4348 KB | Output is correct |
35 | Correct | 179 ms | 4732 KB | Output is correct |
36 | Correct | 150 ms | 4776 KB | Output is correct |
37 | Correct | 381 ms | 4776 KB | Output is correct |
38 | Correct | 91 ms | 5036 KB | Output is correct |
39 | Correct | 330 ms | 5036 KB | Output is correct |
40 | Correct | 193 ms | 5036 KB | Output is correct |
41 | Correct | 230 ms | 5036 KB | Output is correct |
42 | Correct | 306 ms | 5036 KB | Output is correct |
43 | Correct | 303 ms | 5036 KB | Output is correct |
44 | Correct | 330 ms | 5036 KB | Output is correct |
45 | Correct | 622 ms | 5036 KB | Output is correct |
46 | Correct | 807 ms | 5372 KB | Output is correct |
47 | Correct | 605 ms | 5372 KB | Output is correct |
48 | Correct | 602 ms | 5372 KB | Output is correct |
49 | Correct | 806 ms | 5424 KB | Output is correct |
50 | Correct | 851 ms | 5424 KB | Output is correct |