답안 #5030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5030 2014-01-28T13:56:55 Z cki86201 결혼 문제 (IZhO14_marriage) C++
62 / 100
1500 ms 3052 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

//for 72point, O(N(K+M));

vector <int> E[30030];

int n, m, now, mat, ans, prev;
int yx[2020];
int vis[30030],in;

bool dfs(int x)
{
	vis[x] = in;
	for(size_t i=0;i<E[x].size();i++)
		if(!yx[E[x][i]] || (vis[yx[E[x][i]]] != in && dfs(yx[E[x][i]]))){
			yx[E[x][i]] = x;
			return true;
		}
	return false;
}

int main()
{
	int k, i;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		E[x].push_back(y);
	}
	for(i=1;i<=n;i++){
		if(dfs(in=i))mat++;
		if(mat == m){
			int mn = 1;
			for(int j=2;j<=m;j++)if(yx[j] < yx[mn])mn = j;
			ans += (yx[mn] - prev) * (n-i+1);
			prev = yx[mn];
			yx[mn] = 0;
			mat--;
		}
	}
	if(mat == m-1){
		int mx=1, mn=n;
		for(int j=1;j<=m;j++)mx=max(mx,yx[j]), mn=min(mn,yx[j]?yx[j]:n);
		ans += (mn - prev - 1) * (n - mx + 1);
	}
	printf("%d",ans);
	return 0;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:28:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&m,&k);
                          ^
marriage.cpp:31:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 1996 KB Output isn't correct
2 Incorrect 0 ms 1996 KB Output isn't correct
3 Correct 0 ms 1996 KB Output is correct
4 Correct 0 ms 1996 KB Output is correct
5 Correct 0 ms 1996 KB Output is correct
6 Correct 0 ms 1996 KB Output is correct
7 Correct 0 ms 1996 KB Output is correct
8 Incorrect 0 ms 1996 KB Output isn't correct
9 Correct 0 ms 1996 KB Output is correct
10 Correct 0 ms 1996 KB Output is correct
11 Correct 0 ms 1996 KB Output is correct
12 Correct 0 ms 1996 KB Output is correct
13 Incorrect 0 ms 1996 KB Output isn't correct
14 Correct 0 ms 1996 KB Output is correct
15 Incorrect 0 ms 1996 KB Output isn't correct
16 Correct 0 ms 1996 KB Output is correct
17 Correct 0 ms 1996 KB Output is correct
18 Correct 0 ms 1996 KB Output is correct
19 Correct 0 ms 1996 KB Output is correct
20 Correct 0 ms 1996 KB Output is correct
21 Correct 0 ms 1996 KB Output is correct
22 Correct 0 ms 1996 KB Output is correct
23 Correct 0 ms 1996 KB Output is correct
24 Correct 0 ms 1996 KB Output is correct
25 Correct 3 ms 2128 KB Output is correct
26 Incorrect 0 ms 1996 KB Output isn't correct
27 Correct 0 ms 1996 KB Output is correct
28 Correct 0 ms 1996 KB Output is correct
29 Incorrect 3 ms 2128 KB Output isn't correct
30 Incorrect 3 ms 2128 KB Output isn't correct
31 Correct 16 ms 2260 KB Output is correct
32 Incorrect 9 ms 2128 KB Output isn't correct
33 Correct 0 ms 1996 KB Output is correct
34 Correct 0 ms 1996 KB Output is correct
35 Correct 76 ms 2524 KB Output is correct
36 Correct 53 ms 2524 KB Output is correct
37 Correct 46 ms 2392 KB Output is correct
38 Incorrect 143 ms 2788 KB Output isn't correct
39 Correct 29 ms 2128 KB Output is correct
40 Correct 0 ms 2260 KB Output is correct
41 Incorrect 19 ms 2260 KB Output isn't correct
42 Incorrect 186 ms 2392 KB Output isn't correct
43 Incorrect 246 ms 2392 KB Output isn't correct
44 Incorrect 563 ms 2656 KB Output isn't correct
45 Incorrect 13 ms 2656 KB Output isn't correct
46 Execution timed out 1500 ms 3052 KB Execution timed out
47 Incorrect 1299 ms 2920 KB Output isn't correct
48 Incorrect 1279 ms 2920 KB Output isn't correct
49 Execution timed out 1500 ms 3052 KB Execution timed out
50 Correct 29 ms 2128 KB Output is correct