# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38588 | alenam0161 | Marriage questions (IZhO14_marriage) | C++14 | 1500 ms | 4948 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ad push_back
using namespace std;
const int N = 40007 , M = 3007;
vector <int> g[N],g1[M];
bool used1[N],used2[M];
int ma[M],na[N];
bool try_kuhn(int x)
{
if (used1[x]) return false;
used1[x]=true;
int i;
for (auto to:g[x])
if (ma[to]==0 || try_kuhn(ma[to]))
{
ma[to]=x;
na[x]=to;
return true;
}
return false;
}
int l,r=0;
bool try_kuhn2(int x)
{
if (used2[x]) return false;
used2[x]=true;
int i;
for (auto to:g1[x])
if (to>l && to<=r && na[to]==0 || try_kuhn(na[to]))
{
na[to]=x;
ma[x]=to;
return true;
}
return false;
}
int main()
{
int i,n,m,k,x,y;
scanf("%d%d%d",&n,&m,&k);
for (i=1;i<=k;i++)
{
scanf("%d%d",&x,&y);
g[x].ad(y);
g1[y].ad(x);
}
long long ans=0;
int how=0;
for (l=1;l<=n-m+1;l++)
{
while (how!=m && r<n)
{
r++;
memset(used1,0,sizeof used1);
how+=try_kuhn(r);
}
if ( how == m ) ans += n - r + 1;
if (na[l]==0) continue;
memset(used2,0,sizeof( used2));
int gag=na[l];
ma[na[l]]=0;
na[l]=0;
how--;
how+=try_kuhn2(x);
}
cout<<ans<<"\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |