Submission #90400

# Submission time Handle Problem Language Result Execution time Memory
90400 2018-12-21T14:25:09 Z mirbek01 Marriage questions (IZhO14_marriage) C++17
66 / 100
1500 ms 5244 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 2;

int n, m, k, mt[N], used[N], ans, L, R;
vector <int> g[N], vr, mr;

bool dfs(int v){
      if(used[v])
            return 0;
      vr.push_back(v);
      used[v] = 1;
      for(int to : g[v]){
            if((to > R || to < L) && to <= n)
                  continue;
            if(mt[to] == -1 || dfs(mt[to])){
                  if(mt[to] == -1)
                        mr.push_back(to);
                  if(mt[v] == -1)
                        mr.push_back(v);
                  mt[to] = v;
                  mt[v] = to;
                  return true;
            }
      }
      return false;
}

bool check(){
      for(int i = 0; i < (int)mr.size(); i ++)
            mt[ mr[i] ] = -1;
      mr.clear();
      for(int i = n + 1; i <= n + m; i ++){
            for(int j = 0; j < (int)vr.size(); j ++){
                  used[ vr[j] ] = 0;
            }
            vr.clear();
            dfs(i);
      }
      for(int i = n + 1; i <= n + m; i ++){
            if(mt[i] == -1)
                  return false;
      }
      return true;
}

int main(){
      scanf("%d %d %d", &n, &m, &k);

      for(int i = 1; i <= k; i ++){
            int a, b;
            scanf("%d %d", &a, &b);
            g[a].push_back(b + n);
            g[b + n].push_back(a);
      }

      memset(mt, -1, sizeof(mt));

      int pt = 1;

      for(int i = 1; i <= n; i ++){
            int lo = 1, hi = i;
            L = i;
            while(pt + 1 <= n){
                  R = pt;
                  if(!check())
                      pt ++;
                  else
                        break;
            }
            R = pt;
            if(check())
                  ans += n - pt + 1;
      }

      printf("%d", ans);
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:64:17: warning: unused variable 'lo' [-Wunused-variable]
             int lo = 1, hi = i;
                 ^~
marriage.cpp:64:25: warning: unused variable 'hi' [-Wunused-variable]
             int lo = 1, hi = i;
                         ^~
marriage.cpp:50:12: 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:54:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3064 KB Output is correct
2 Correct 4 ms 3068 KB Output is correct
3 Correct 4 ms 3128 KB Output is correct
4 Correct 4 ms 3144 KB Output is correct
5 Correct 4 ms 3204 KB Output is correct
6 Correct 4 ms 3220 KB Output is correct
7 Correct 4 ms 3220 KB Output is correct
8 Correct 4 ms 3348 KB Output is correct
9 Correct 4 ms 3348 KB Output is correct
10 Correct 4 ms 3348 KB Output is correct
11 Correct 4 ms 3348 KB Output is correct
12 Correct 4 ms 3348 KB Output is correct
13 Correct 4 ms 3348 KB Output is correct
14 Correct 4 ms 3348 KB Output is correct
15 Correct 4 ms 3348 KB Output is correct
16 Correct 4 ms 3348 KB Output is correct
17 Correct 4 ms 3348 KB Output is correct
18 Correct 4 ms 3348 KB Output is correct
19 Correct 16 ms 3348 KB Output is correct
20 Correct 7 ms 3348 KB Output is correct
21 Correct 4 ms 3348 KB Output is correct
22 Correct 6 ms 3348 KB Output is correct
23 Correct 13 ms 3348 KB Output is correct
24 Correct 11 ms 3348 KB Output is correct
25 Correct 247 ms 3412 KB Output is correct
26 Correct 73 ms 3412 KB Output is correct
27 Correct 6 ms 3412 KB Output is correct
28 Correct 46 ms 3580 KB Output is correct
29 Correct 46 ms 3580 KB Output is correct
30 Correct 33 ms 3580 KB Output is correct
31 Execution timed out 1566 ms 3964 KB Time limit exceeded
32 Correct 1356 ms 3964 KB Output is correct
33 Correct 15 ms 3964 KB Output is correct
34 Execution timed out 1559 ms 3964 KB Time limit exceeded
35 Execution timed out 1574 ms 4348 KB Time limit exceeded
36 Execution timed out 1579 ms 4348 KB Time limit exceeded
37 Execution timed out 1582 ms 4348 KB Time limit exceeded
38 Execution timed out 1586 ms 4604 KB Time limit exceeded
39 Execution timed out 1572 ms 4604 KB Time limit exceeded
40 Execution timed out 1546 ms 4604 KB Time limit exceeded
41 Execution timed out 1571 ms 4604 KB Time limit exceeded
42 Correct 1233 ms 4604 KB Output is correct
43 Execution timed out 1579 ms 4604 KB Time limit exceeded
44 Execution timed out 1554 ms 4740 KB Time limit exceeded
45 Execution timed out 1586 ms 4740 KB Time limit exceeded
46 Execution timed out 1578 ms 5116 KB Time limit exceeded
47 Execution timed out 1564 ms 5116 KB Time limit exceeded
48 Execution timed out 1573 ms 5116 KB Time limit exceeded
49 Execution timed out 1548 ms 5244 KB Time limit exceeded
50 Execution timed out 1558 ms 5244 KB Time limit exceeded