# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90024 | Bodo171 | Marriage questions (IZhO14_marriage) | C++14 | 1585 ms | 2656 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 <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax=30005;
vector<int> v[nmax];
int l[nmax],r[nmax];
bool viz[nmax];
bool changed;
int n,m,i,j,k,a,b,p,cupl,ans;
bool cup(int x)
{
if(viz[x])
return 0;
viz[x]=1;
for(int it=0;it<v[x].size();it++)
if((!r[v[x][it]])||cup(r[v[x][it]]))
{
l[x]=v[x][it];
r[v[x][it]]=x;
return 1;
}
return 0;
}
void cc()
{
changed=1;
while(changed&&cupl<m)
{
changed=0;
for(j=p; j<=i; j++)
if((!l[j])&&cup(j))
{
cupl++;
changed=1;
}
for(j=p; j<=i; j++)
viz[j]=0;
}
}
int main()
{
//freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n>>m>>k;
for(i=1;i<=k;i++)
{
cin>>a>>b;
v[a].push_back(b);
}
p=1;
for(i=1;i<=n;i++)
{
if(i>=m)cc();
while(cupl==m)
{
if(l[p])
r[l[p]]=0,cupl--;
p++;
cc();
}
ans+=(p-1);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |