Submission #340686

#TimeUsernameProblemLanguageResultExecution timeMemory
340686KerimMarriage questions (IZhO14_marriage)C++17
100 / 100
837 ms4460 KiB
#include "bits/stdc++.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} int vis[MAXN],l,r=1,ver; vector<int>adj[MAXN]; int match[MAXN]; bool dfs(int nd){ if(vis[nd]==ver)return 0; vis[nd]=ver; tr(it,adj[nd]) if(l<=*it and *it<=r) if(match[*it]==-1 or dfs(match[*it])){ match[*it]=nd; return 1; } return 0; } int main(){ //freopen("file.in", "r", stdin); int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++){ int a,b; scanf("%d%d",&a,&b); adj[b].pb(a); } vector<int>need; for(int i=1;i<=m;i++) need.pb(i); for(int i=1;i<=n;i++) match[i]=-1; ll ans=0; for(l=1;max(r,l)<=n;l++){ while(!need.empty()){ int nd=need.back();ver++; while(r<=n and !dfs(nd)) r++,ver++; if(r>n) break; need.ppb(); } ans+=n-r+1; if(~match[l]) need.pb(match[l]),match[l]=-1; } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

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