# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
341223 | juggernaut | Marriage questions (IZhO14_marriage) | C++14 | 1595 ms | 4972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100005];
int mt[100005];
int n,m,q;
bool used[100001];
int X,Y;
bool kuhn(int v){
if(used[v]||v<X||v>Y)return false;
used[v]=true;
for(int to:g[v]){
if(mt[to]==0||kuhn(mt[to])){
mt[to]=v;
return true;
}
}
return false;
}
bool check(int l,int r){
X=l,Y=r;
for(int i=1;i<=n;i++)mt[i]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)used[j]=false;
kuhn(i);
}
int c=0;
for(int i=1;i<=n;i++)if(mt[i])c++;
return c==m;
}
int main(){
scanf("%d%d%d",&n,&m,&q);
while(q--){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
}
int ans=0;
for(int GL=1;GL<=n;GL++){
int l=GL,r=n;
while(l<r){
int mid=(l+r)>>1;
if(check(GL,mid))r=mid;
else l=mid+1;
}
if(check(GL,l))ans+=n-l+1;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |