Submission #90399

# Submission time Handle Problem Language Result Execution time Memory
90399 2018-12-21T14:13:22 Z mirbek01 Marriage questions (IZhO14_marriage) C++17
60 / 100
1500 ms 13916 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 2;

int n, m, k, mt[N], used[N], ans, y;
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 < y)
                  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);
      }

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

      for(int i = 1; i <= n; i ++){
            for(int j = 0; j < g[i].size(); j ++){
                  g[g[i][j]].push_back(i);
            }
            int lo = 1, hi = i, m = 0;
            while(lo <= hi){
                  int md = (lo + hi) >> 1;
                  y = md;
                  if(check())
                        lo = md + 1, m = md;
                  else
                        hi = md - 1;
            }
            ans += m;
      }

      printf("%d", ans);
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0; j < g[i].size(); j ++){
                            ~~^~~~~~~~~~~~~
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 3 ms 3248 KB Output is correct
3 Correct 4 ms 3248 KB Output is correct
4 Correct 3 ms 3248 KB Output is correct
5 Correct 4 ms 3248 KB Output is correct
6 Correct 3 ms 3248 KB Output is correct
7 Correct 4 ms 3252 KB Output is correct
8 Correct 4 ms 3260 KB Output is correct
9 Correct 3 ms 3340 KB Output is correct
10 Correct 4 ms 3340 KB Output is correct
11 Correct 4 ms 3344 KB Output is correct
12 Correct 4 ms 3344 KB Output is correct
13 Correct 4 ms 3344 KB Output is correct
14 Correct 4 ms 3344 KB Output is correct
15 Correct 4 ms 3480 KB Output is correct
16 Correct 4 ms 3480 KB Output is correct
17 Correct 4 ms 3480 KB Output is correct
18 Correct 4 ms 3480 KB Output is correct
19 Correct 41 ms 3480 KB Output is correct
20 Correct 13 ms 3480 KB Output is correct
21 Correct 4 ms 3480 KB Output is correct
22 Correct 8 ms 3480 KB Output is correct
23 Correct 28 ms 3480 KB Output is correct
24 Correct 25 ms 3480 KB Output is correct
25 Execution timed out 1562 ms 3924 KB Time limit exceeded
26 Correct 223 ms 3924 KB Output is correct
27 Correct 10 ms 3924 KB Output is correct
28 Correct 114 ms 3924 KB Output is correct
29 Correct 80 ms 3924 KB Output is correct
30 Correct 60 ms 3924 KB Output is correct
31 Execution timed out 1571 ms 4536 KB Time limit exceeded
32 Execution timed out 1552 ms 4536 KB Time limit exceeded
33 Correct 45 ms 4536 KB Output is correct
34 Execution timed out 1571 ms 4536 KB Time limit exceeded
35 Execution timed out 1567 ms 5824 KB Time limit exceeded
36 Execution timed out 1571 ms 6440 KB Time limit exceeded
37 Execution timed out 1568 ms 6460 KB Time limit exceeded
38 Execution timed out 1575 ms 7824 KB Time limit exceeded
39 Execution timed out 1571 ms 7824 KB Time limit exceeded
40 Execution timed out 1563 ms 7824 KB Time limit exceeded
41 Execution timed out 1561 ms 7824 KB Time limit exceeded
42 Execution timed out 1573 ms 7988 KB Time limit exceeded
43 Execution timed out 1578 ms 8508 KB Time limit exceeded
44 Execution timed out 1559 ms 9552 KB Time limit exceeded
45 Execution timed out 1575 ms 9800 KB Time limit exceeded
46 Execution timed out 1571 ms 11040 KB Time limit exceeded
47 Execution timed out 1570 ms 11884 KB Time limit exceeded
48 Execution timed out 1575 ms 12968 KB Time limit exceeded
49 Execution timed out 1564 ms 13916 KB Time limit exceeded
50 Execution timed out 1567 ms 13916 KB Time limit exceeded