Submission #340686

# Submission time Handle Problem Language Result Execution time Memory
340686 2020-12-28T07:49:49 Z Kerim Marriage questions (IZhO14_marriage) C++17
100 / 100
837 ms 4460 KB
#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

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 time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 3 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 3 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 4 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 2 ms 2668 KB Output is correct
25 Correct 42 ms 2796 KB Output is correct
26 Correct 7 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 4 ms 2796 KB Output is correct
30 Correct 4 ms 2796 KB Output is correct
31 Correct 310 ms 3436 KB Output is correct
32 Correct 3 ms 2796 KB Output is correct
33 Correct 3 ms 2668 KB Output is correct
34 Correct 3 ms 2668 KB Output is correct
35 Correct 120 ms 4028 KB Output is correct
36 Correct 87 ms 3820 KB Output is correct
37 Correct 837 ms 3640 KB Output is correct
38 Correct 22 ms 4076 KB Output is correct
39 Correct 49 ms 2924 KB Output is correct
40 Correct 6 ms 2924 KB Output is correct
41 Correct 10 ms 3052 KB Output is correct
42 Correct 9 ms 3180 KB Output is correct
43 Correct 13 ms 3456 KB Output is correct
44 Correct 21 ms 4140 KB Output is correct
45 Correct 11 ms 3308 KB Output is correct
46 Correct 37 ms 4272 KB Output is correct
47 Correct 28 ms 4332 KB Output is correct
48 Correct 31 ms 4204 KB Output is correct
49 Correct 32 ms 4460 KB Output is correct
50 Correct 157 ms 2924 KB Output is correct