# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
38525 | alenam0161 | 결혼 문제 (IZhO14_marriage) | C++14 | 1500 ms | 3124 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+7;
vector<int> g[N],g1[N],gag,kox;
int n,m,k;
bool used[N];
int ma[N];
bool try_khun(int v){
if(used[v]==true)return false;
used[v]=true;
gag.push_back(v);
for(auto to:g[v]){
if(ma[to]==-1||try_khun(ma[to])){
if(ma[to]==-1)kox.push_back(to);
ma[to]=v;
return true;
}
}
return false;
}
int main(){
memset(ma,-1,sizeof(ma));
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;++i){
int u,v;
scanf("%d%d",&v,&u);
g[v].push_back(u);
g1[u].push_back(v);
}
int how=0;
long long ans=0;
int l=1;
bool ok=false;
for(int i=1;i<=n;++i){
if(try_khun(i))how++;
bool ok=false;
while(how==m||ok==false){
l++;
ok=true;
how=0;
for(int to:kox){
ma[to]=-1;
}
kox.clear();
for(int j=l;j<=i;++j){
for(int to:gag)used[to]=false;
gag.clear();
how+=try_khun(j);
}
}
l--;
for(int to:gag)used[to]=false;
gag.clear();
how+=try_khun(l);
// cout<<l<<" "<<i<<" "<<how<<endl;
if(how==m)
ans+=l;
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |