Submission #96058

# Submission time Handle Problem Language Result Execution time Memory
96058 2019-02-05T13:55:24 Z Kastanda Marriage questions (IZhO14_marriage) C++11
66 / 100
242 ms 1912 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;
bool DFS(int v)
{
    if (M[v] == ts)
        return 0;
    M[v] = ts;
    for (int i = 0; i < (int)Adj[v].size() && Adj[v][i] <= r; 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 void Match()
{
    while (qu.size())
    {
        int v = qu.front();
        qu.pop(); ts ++;
        if (!DFS(v))
        {
            qu.push(v);
            return ;
        }
    }
}
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:34: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:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1272 KB Output isn't correct
2 Incorrect 2 ms 1272 KB Output isn't correct
3 Incorrect 3 ms 1272 KB Output isn't correct
4 Correct 2 ms 1272 KB Output is correct
5 Correct 2 ms 1272 KB Output is correct
6 Correct 2 ms 1192 KB Output is correct
7 Incorrect 2 ms 1276 KB Output isn't correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 2 ms 1272 KB Output is correct
10 Correct 2 ms 1276 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 2 ms 1272 KB Output is correct
13 Correct 2 ms 1272 KB Output is correct
14 Incorrect 2 ms 1276 KB Output isn't correct
15 Incorrect 3 ms 1276 KB Output isn't correct
16 Correct 2 ms 1272 KB Output is correct
17 Correct 2 ms 1144 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Incorrect 3 ms 1272 KB Output isn't correct
20 Incorrect 2 ms 1272 KB Output isn't correct
21 Correct 2 ms 1272 KB Output is correct
22 Correct 3 ms 1272 KB Output is correct
23 Correct 2 ms 1272 KB Output is correct
24 Correct 8 ms 1316 KB Output is correct
25 Incorrect 4 ms 1400 KB Output isn't correct
26 Incorrect 3 ms 1272 KB Output isn't correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 4 ms 1272 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Incorrect 13 ms 1500 KB Output isn't correct
32 Incorrect 4 ms 1272 KB Output isn't correct
33 Correct 3 ms 1276 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 105 ms 1912 KB Output is correct
36 Correct 76 ms 1756 KB Output is correct
37 Incorrect 17 ms 1656 KB Output isn't correct
38 Correct 20 ms 1784 KB Output is correct
39 Correct 77 ms 1400 KB Output is correct
40 Correct 6 ms 1400 KB Output is correct
41 Incorrect 8 ms 1400 KB Output isn't correct
42 Correct 8 ms 1400 KB Output is correct
43 Correct 12 ms 1500 KB Output is correct
44 Correct 20 ms 1784 KB Output is correct
45 Incorrect 10 ms 1528 KB Output isn't correct
46 Incorrect 24 ms 1912 KB Output isn't correct
47 Correct 21 ms 1784 KB Output is correct
48 Correct 20 ms 1784 KB Output is correct
49 Incorrect 25 ms 1912 KB Output isn't correct
50 Correct 242 ms 1468 KB Output is correct