Submission #594252

# Submission time Handle Problem Language Result Execution time Memory
594252 2022-07-12T09:30:09 Z Pety Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
202 ms 26180 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define ll long long

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

vector<vector<int>> p, ans;
vector<int>idk, comp;
int n, rep[1002], selected, viz[1002];

void dfs1 (int nod) {
  rep[nod] = selected;
  viz[nod] = 1;
  for (int i = 0; i < n; i++)
    if (p[nod][i] == 1 && !viz[i])
     dfs1(i);
  
}

void dfs2 (int nod) {
  comp.push_back(nod);
  viz[nod] = 1;
  for (auto it : idk) 
    if (!viz[it] && p[nod][it] == 2)
      dfs2(it);
}



int construct (vector<vector<int>>aux) {
  p = aux;
  n = p.size();
  ans.resize(n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (p[i][j] == 3)
        return 0;
  for (int i = 0; i < n; i++)
    ans[i].resize(n);
  for (int i = 0; i < n; i++) 
    if (!viz[i]) {
      selected = i;
      idk.push_back(selected);
      dfs1(i);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (rep[i] == rep[j] && p[i][j] != 1)
        return 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (rep[i] != rep[j] && p[i][j] != p[rep[i]][rep[j]])
        return 0;
  for (auto it : idk) {
    int aux = -1;
    for (int j = 0; j < n; j++)
      if (rep[j] == it) {
        if (aux != -1)
          ans[aux][j] = ans[j][aux] = 1;
        aux = j;
      }
  }
  memset(viz, 0, sizeof(viz));
  for (auto it : idk) {
    if (!viz[it]) {
      comp.clear();
      dfs2(it);
      if (comp.size() == 1)
        continue;
      if (comp.size() == 2)
        return 0;
      for (int i = 0; i < comp.size(); i++) 
        for (int j = i + 1; j < comp.size(); j++)
          if (p[comp[i]][comp[j]] != 2)
            return 0;
      for (int i = 0; i < comp.size(); i++) 
        ans[comp[i]][comp[(i + 1) % comp.size()]] = ans[comp[(i + 1) % comp.size()]][comp[i]] = 1;
    }
  }
  build(ans);
  return 1;
}

// int main ()
// {
//   cout << construct({{1, 2, 0, 2}, {2, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
//   return 0;
// }



Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       for (int i = 0; i < comp.size(); i++)
      |                       ~~^~~~~~~~~~~~~
supertrees.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int j = i + 1; j < comp.size(); j++)
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:79:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       for (int i = 0; i < comp.size(); i++)
      |                       ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 169 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 169 ms 25976 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 183 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 82 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6676 KB Output is correct
21 Correct 174 ms 25996 KB Output is correct
22 Correct 202 ms 25992 KB Output is correct
23 Correct 174 ms 25932 KB Output is correct
24 Correct 178 ms 26004 KB Output is correct
25 Correct 81 ms 16020 KB Output is correct
26 Correct 66 ms 16012 KB Output is correct
27 Correct 196 ms 25988 KB Output is correct
28 Correct 162 ms 26008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1340 KB Output is correct
9 Correct 169 ms 25992 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 165 ms 26060 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 77 ms 16136 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 46 ms 6688 KB Output is correct
22 Correct 191 ms 25904 KB Output is correct
23 Correct 181 ms 25948 KB Output is correct
24 Correct 184 ms 26180 KB Output is correct
25 Correct 94 ms 16008 KB Output is correct
26 Correct 70 ms 16080 KB Output is correct
27 Correct 173 ms 25996 KB Output is correct
28 Correct 170 ms 26040 KB Output is correct
29 Correct 98 ms 16020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 45 ms 6748 KB Output is correct
5 Correct 178 ms 25972 KB Output is correct
6 Correct 196 ms 26112 KB Output is correct
7 Correct 177 ms 25940 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 56 ms 6692 KB Output is correct
10 Correct 165 ms 26004 KB Output is correct
11 Correct 172 ms 25952 KB Output is correct
12 Correct 173 ms 25948 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 47 ms 6672 KB Output is correct
17 Correct 169 ms 26132 KB Output is correct
18 Correct 189 ms 25992 KB Output is correct
19 Correct 176 ms 26000 KB Output is correct
20 Correct 166 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 169 ms 25976 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 183 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 82 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6676 KB Output is correct
21 Correct 174 ms 25996 KB Output is correct
22 Correct 202 ms 25992 KB Output is correct
23 Correct 174 ms 25932 KB Output is correct
24 Correct 178 ms 26004 KB Output is correct
25 Correct 81 ms 16020 KB Output is correct
26 Correct 66 ms 16012 KB Output is correct
27 Correct 196 ms 25988 KB Output is correct
28 Correct 162 ms 26008 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 288 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1340 KB Output is correct
37 Correct 169 ms 25992 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 165 ms 26060 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 77 ms 16136 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6688 KB Output is correct
50 Correct 191 ms 25904 KB Output is correct
51 Correct 181 ms 25948 KB Output is correct
52 Correct 184 ms 26180 KB Output is correct
53 Correct 94 ms 16008 KB Output is correct
54 Correct 70 ms 16080 KB Output is correct
55 Correct 173 ms 25996 KB Output is correct
56 Correct 170 ms 26040 KB Output is correct
57 Correct 98 ms 16020 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 5 ms 960 KB Output is correct
61 Correct 75 ms 16020 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 42 ms 6748 KB Output is correct
66 Correct 93 ms 16004 KB Output is correct
67 Correct 75 ms 16012 KB Output is correct
68 Correct 68 ms 16076 KB Output is correct
69 Correct 68 ms 16016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 169 ms 25976 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 183 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 82 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6676 KB Output is correct
21 Correct 174 ms 25996 KB Output is correct
22 Correct 202 ms 25992 KB Output is correct
23 Correct 174 ms 25932 KB Output is correct
24 Correct 178 ms 26004 KB Output is correct
25 Correct 81 ms 16020 KB Output is correct
26 Correct 66 ms 16012 KB Output is correct
27 Correct 196 ms 25988 KB Output is correct
28 Correct 162 ms 26008 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 288 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1340 KB Output is correct
37 Correct 169 ms 25992 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 165 ms 26060 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 77 ms 16136 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6688 KB Output is correct
50 Correct 191 ms 25904 KB Output is correct
51 Correct 181 ms 25948 KB Output is correct
52 Correct 184 ms 26180 KB Output is correct
53 Correct 94 ms 16008 KB Output is correct
54 Correct 70 ms 16080 KB Output is correct
55 Correct 173 ms 25996 KB Output is correct
56 Correct 170 ms 26040 KB Output is correct
57 Correct 98 ms 16020 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 45 ms 6748 KB Output is correct
62 Correct 178 ms 25972 KB Output is correct
63 Correct 196 ms 26112 KB Output is correct
64 Correct 177 ms 25940 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 56 ms 6692 KB Output is correct
67 Correct 165 ms 26004 KB Output is correct
68 Correct 172 ms 25952 KB Output is correct
69 Correct 173 ms 25948 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 47 ms 6672 KB Output is correct
74 Correct 169 ms 26132 KB Output is correct
75 Correct 189 ms 25992 KB Output is correct
76 Correct 176 ms 26000 KB Output is correct
77 Correct 166 ms 25976 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 5 ms 960 KB Output is correct
81 Correct 75 ms 16020 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 42 ms 6748 KB Output is correct
86 Correct 93 ms 16004 KB Output is correct
87 Correct 75 ms 16012 KB Output is correct
88 Correct 68 ms 16076 KB Output is correct
89 Correct 68 ms 16016 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 68 ms 12048 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 19 ms 3684 KB Output is correct
98 Correct 69 ms 14084 KB Output is correct
99 Correct 68 ms 14072 KB Output is correct
100 Correct 71 ms 14068 KB Output is correct
101 Correct 63 ms 14084 KB Output is correct
102 Correct 64 ms 14088 KB Output is correct
103 Correct 79 ms 14068 KB Output is correct
104 Correct 71 ms 14084 KB Output is correct
105 Correct 76 ms 14072 KB Output is correct