# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90021 | Bodo171 | 결혼 문제 (IZhO14_marriage) | C++14 | 1575 ms | 12316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]])
{
l[x]=v[x][it];
r[v[x][it]]=x;
return 1;
}
for(int it=0;it<v[x].size();it++)
if(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)
{
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++)
{
cc();
while(cupl==m)
{
if(l[p])
r[l[p]]=0,cupl--;
p++;
cc();
}
ans+=(p-1);
}
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |