Submission #341229

#TimeUsernameProblemLanguageResultExecution timeMemory
341229juggernautMarriage questions (IZhO14_marriage)C++14
52 / 100
1595 ms3956 KiB
#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); if(n<m||q<m)return puts("0"); 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++){ if(!check(GL,n))continue; int l=GL,r=n+1; while(l<r){ int mid=(l+r)>>1; if(check(GL,mid))r=mid; else l=mid+1; } ans+=n-l+1; } cout<<ans; }

Compilation message (stderr)

marriage.cpp: In function 'int main()':
marriage.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
marriage.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...