답안 #167184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167184 2019-12-06T09:13:27 Z Dovran 결혼 문제 (IZhO14_marriage) C++11
100 / 100
985 ms 2936 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int MAXN = 34004;
int n, m, k, ts, l, r, MC[MAXN], M[MAXN];
vector < int > Adj[MAXN];
queue < int > qu;
int DFS(int v)
{
    if (M[v] == ts)
        return 0;
    M[v] = ts;
    for (int i = 0; i < (int)Adj[v].size(); i++)
        if (l <= Adj[v][i] && Adj[v][i] <= r)
            if (MC[Adj[v][i]] == -1 || DFS(MC[Adj[v][i]]))
                return MC[Adj[v][i]] = v, 1;
    return 0;
}
inline int Match()
{
    while (qu.size())
    {
        int v = qu.front();
        qu.pop(); ts ++;
        if (!DFS(v))
            return qu.push(v), 1;
    }
    return 1;
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= k; i++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[u].pb(v);
    }
    int tot = 0;
    memset(MC, -1, sizeof(MC));
    for (int i = 1; i <= m; i++)
        qu.push(i);
    for (l = 1; l <= n; l ++)
    {
        r = max(r, l); Match();
        while (r < n && qu.size())
            r ++, Match();
        if (qu.size())
            break;
        tot += n - r + 1;
        if (MC[l] != -1)
            qu.push(MC[l]), MC[l] = -1;
    }
    return !printf("%d\n", tot);
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:32:10: 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:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 4 ms 1320 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 3 ms 1272 KB Output is correct
14 Correct 3 ms 1272 KB Output is correct
15 Correct 3 ms 1272 KB Output is correct
16 Correct 3 ms 1272 KB Output is correct
17 Correct 3 ms 1272 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 3 ms 1272 KB Output is correct
21 Correct 3 ms 1272 KB Output is correct
22 Correct 3 ms 1272 KB Output is correct
23 Correct 3 ms 1272 KB Output is correct
24 Correct 3 ms 1296 KB Output is correct
25 Correct 46 ms 1464 KB Output is correct
26 Correct 8 ms 1272 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 5 ms 1400 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 330 ms 2100 KB Output is correct
32 Correct 14 ms 1400 KB Output is correct
33 Correct 3 ms 1272 KB Output is correct
34 Correct 6 ms 1272 KB Output is correct
35 Correct 139 ms 2552 KB Output is correct
36 Correct 93 ms 2488 KB Output is correct
37 Correct 985 ms 2292 KB Output is correct
38 Correct 25 ms 2552 KB Output is correct
39 Correct 117 ms 1528 KB Output is correct
40 Correct 7 ms 1532 KB Output is correct
41 Correct 10 ms 1656 KB Output is correct
42 Correct 11 ms 1656 KB Output is correct
43 Correct 25 ms 1964 KB Output is correct
44 Correct 24 ms 2684 KB Output is correct
45 Correct 13 ms 1784 KB Output is correct
46 Correct 60 ms 2820 KB Output is correct
47 Correct 27 ms 2808 KB Output is correct
48 Correct 25 ms 2680 KB Output is correct
49 Correct 117 ms 2936 KB Output is correct
50 Correct 266 ms 1528 KB Output is correct