# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443032 | leaked | Marriage questions (IZhO14_marriage) | C++14 | 1600 ms | 3164 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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define vec vector
#define sz(x) ( int)x.size()
#define m_p make_pair
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef unsigned long long ull;
auto rng=bind(uniform_int_distribution<int>(1,1000),mt19937(time(0)));
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const int N=3e4+1;
const int K=165;
const int M=2001;
vec<int> g[N+M];
int uk;
int mt[N+M];
int h[N+M],u[N+M],tt,n,m;
int tr;
bool kuhn(int v){
if(u[v]==tt) return 0;
u[v]=tt;
for(auto &z : g[v]){
if(h[z] && (mt[z]==-1 || kuhn(mt[z]))){
mt[z]=v;mt[v]=z;
return 1;
}
}
return 0;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int k;
cin>>n>>m>>k;
for(int i=0;i<k;i++){
int v,u;
cin>>v>>u;--v;--u;
g[v].pb(u+n);
g[u+n].pb(v);
}
fill(mt,mt+n+m,-1);
for(int i=0;i<m;i++) h[i+n]=1;
int r=-1;
int c=0;
ll ans=0;
for(int l=0;l<n;l++){
if(l){
h[l-1]=0;
if(mt[l-1]!=-1){
tt++;
mt[mt[l-1]]=-1;
c--;c+=kuhn(mt[l-1]);
mt[l-1]=-1;
}
}
while(r<n && c!=m){
r++;tt++;
h[r]=1;c+=kuhn(r);
}
ans+=n-r;
}
cout<<ans;
return 0;
}
/*
5
1 2
2 3
3 4
4 5
5 1
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |