# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341254 | 2020-12-29T10:14:28 Z | juggernaut | Marriage questions (IZhO14_marriage) | C++14 | 826 ms | 1132 KB |
#include<bits/stdc++.h> using namespace std; int n,m,qq,mt[30005],GL,GR,vis[2005],timer; vector<int>g[2005]; queue<int>q; bool kuhn(int v){ if(vis[v]==timer)return false; vis[v]=timer; for(int to:g[v]){ if(to<GL||to>GR)continue; if(!mt[to]||kuhn(mt[to])){ mt[to]=v; return true; } } return false; } bool check(){ while(!q.empty()){ int v=q.front(); q.pop(); timer++; if(!kuhn(v)){ q.push(v); return false; } } return true; } int main(){ scanf("%d%d%d",&n,&m,&qq); while(qq--){ int x,y; scanf("%d%d",&x,&y); g[y].push_back(x); } srand(time(NULL)); for(int i=1;i<=m;i++)random_shuffle(g[i].begin(),g[i].end()); for(int i=1;i<=m;i++)q.push(i); int ans=0; GR=1; for(GL=1;GL<=n;GL++){ while(GR<=n&&!check())GR++; ans+=n-GR+1; if(mt[GL]){ q.push(mt[GL]); mt[GL]=0; } } cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 2 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 376 KB | Output is correct |
25 | Correct | 37 ms | 492 KB | Output is correct |
26 | Correct | 6 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 KB | Output is correct |
29 | Correct | 3 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 364 KB | Output is correct |
31 | Correct | 280 ms | 748 KB | Output is correct |
32 | Correct | 11 ms | 512 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 3 ms | 364 KB | Output is correct |
35 | Correct | 121 ms | 1004 KB | Output is correct |
36 | Correct | 85 ms | 1004 KB | Output is correct |
37 | Correct | 826 ms | 1004 KB | Output is correct |
38 | Correct | 22 ms | 876 KB | Output is correct |
39 | Correct | 89 ms | 492 KB | Output is correct |
40 | Correct | 4 ms | 492 KB | Output is correct |
41 | Correct | 7 ms | 620 KB | Output is correct |
42 | Correct | 8 ms | 620 KB | Output is correct |
43 | Correct | 13 ms | 748 KB | Output is correct |
44 | Correct | 24 ms | 1004 KB | Output is correct |
45 | Correct | 10 ms | 748 KB | Output is correct |
46 | Correct | 48 ms | 1132 KB | Output is correct |
47 | Correct | 26 ms | 1004 KB | Output is correct |
48 | Correct | 25 ms | 1004 KB | Output is correct |
49 | Correct | 93 ms | 1132 KB | Output is correct |
50 | Correct | 273 ms | 492 KB | Output is correct |