Submission #722432

# Submission time Handle Problem Language Result Execution time Memory
722432 2023-04-12T00:08:40 Z Yell0 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
256 ms 45612 KB
#include <bits/stdc++.h>
#include "supertrees.h"
 
using namespace std;
typedef pair<int,int> pii;
 
int construct(vector<vector<int>> p) {
  int N=p.size();
  vector<pii> comps(N);
  for(int i=0;i<N;++i) comps[i]={-1,-1};
  int newcomp=0;
  vector<int> newsubcomp(N,0);
  for(int i=0;i<N;++i) {
    if(comps[i]==pii(-1,-1)) {
      comps[i]={newcomp,newsubcomp[newcomp]++};
      newcomp++;
    }
    else if(comps[i].second<0) comps[i].second=newsubcomp[comps[i].first]++;
    for(int j=i+1;j<N;++j) {
      if(p[i][j]==3) return 0;
      if(comps[j]==pii(-1,-1)) {
        if(p[i][j]==0) continue;
        if(p[i][j]==1) comps[j]=comps[i];
        if(p[i][j]==2) comps[j].first=comps[i].first;
      } else {
        if(p[i][j]==0&&comps[i].first==comps[j].first) return 0;
        if(p[i][j]==1) {
          if(comps[i].second!=comps[j].second) {
            if(comps[j].second>=0) return 0;
            else comps[j].second=comps[i].second;
          }
        }
        if(p[i][j]==2&&(comps[i]==comps[j]||comps[i].first!=comps[j].first)) return 0;
      }
    }
  }
  for(int i=0;i<N;++i) for(int j=i+1;j<N;++j) {
    if(p[i][j]==0&&comps[i].first==comps[j].first) return 0;
    if(p[i][j]==1&&comps[i]!=comps[j]) return 0;
  }
  vector<vector<vector<int>>> gr(N,vector<vector<int>>(N));
  int i=0;
  for(pii p:comps) gr[p.first][p.second].push_back(i++);
  vector<vector<int>> ans(N,vector<int>(N,0));
  for(int i=0;i<newcomp;++i) {
    if(newsubcomp[i]==2) return 0;
    for(int j=0;j<newsubcomp[i];++j) {
      for(int k=1;k<(int)gr[i][j].size();++k) ans[gr[i][j][k]][gr[i][j][0]]=ans[gr[i][j][0]][gr[i][j][k]]=1;
      if(j==0) ans[gr[i][j][0]][gr[i][newsubcomp[i]-1][0]]=ans[gr[i][newsubcomp[i]-1][0]][gr[i][j][0]]=1;
      else ans[gr[i][j][0]][gr[i][j-1][0]]=ans[gr[i][j-1][0]][gr[i][j][0]]=1;
    }
  }
  for(int i=0;i<N;++i) ans[i][i]=0;
  build(ans);
  return 1;
}
# 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 215 ms 45516 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 215 ms 45516 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 2120 KB Output is correct
13 Correct 224 ms 45580 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 76 ms 8068 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 65 ms 11660 KB Output is correct
21 Correct 178 ms 45572 KB Output is correct
22 Correct 256 ms 45504 KB Output is correct
23 Correct 181 ms 45528 KB Output is correct
24 Correct 183 ms 45588 KB Output is correct
25 Correct 69 ms 8072 KB Output is correct
26 Correct 64 ms 8064 KB Output is correct
27 Correct 217 ms 45568 KB Output is correct
28 Correct 177 ms 45612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 2132 KB Output is correct
9 Correct 179 ms 45496 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 2112 KB Output is correct
13 Correct 176 ms 45596 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 72 ms 8068 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 53 ms 11668 KB Output is correct
22 Correct 184 ms 45584 KB Output is correct
23 Correct 184 ms 45572 KB Output is correct
24 Correct 187 ms 45580 KB Output is correct
25 Correct 83 ms 35656 KB Output is correct
26 Correct 69 ms 8140 KB Output is correct
27 Correct 182 ms 45592 KB Output is correct
28 Correct 186 ms 45556 KB Output is correct
29 Correct 83 ms 35596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 52 ms 11656 KB Output is correct
5 Correct 192 ms 45568 KB Output is correct
6 Correct 185 ms 45516 KB Output is correct
7 Correct 186 ms 45552 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 60 ms 11592 KB Output is correct
10 Correct 170 ms 45568 KB Output is correct
11 Correct 225 ms 45544 KB Output is correct
12 Correct 182 ms 45536 KB Output is correct
13 Correct 1 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 44 ms 11656 KB Output is correct
17 Correct 175 ms 45572 KB Output is correct
18 Correct 202 ms 45480 KB Output is correct
19 Correct 194 ms 45500 KB Output is correct
20 Correct 192 ms 45516 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 215 ms 45516 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 2120 KB Output is correct
13 Correct 224 ms 45580 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 76 ms 8068 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 65 ms 11660 KB Output is correct
21 Correct 178 ms 45572 KB Output is correct
22 Correct 256 ms 45504 KB Output is correct
23 Correct 181 ms 45528 KB Output is correct
24 Correct 183 ms 45588 KB Output is correct
25 Correct 69 ms 8072 KB Output is correct
26 Correct 64 ms 8064 KB Output is correct
27 Correct 217 ms 45568 KB Output is correct
28 Correct 177 ms 45612 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 2132 KB Output is correct
37 Correct 179 ms 45496 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 2112 KB Output is correct
41 Correct 176 ms 45596 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 72 ms 8068 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 53 ms 11668 KB Output is correct
50 Correct 184 ms 45584 KB Output is correct
51 Correct 184 ms 45572 KB Output is correct
52 Correct 187 ms 45580 KB Output is correct
53 Correct 83 ms 35656 KB Output is correct
54 Correct 69 ms 8140 KB Output is correct
55 Correct 182 ms 45592 KB Output is correct
56 Correct 186 ms 45556 KB Output is correct
57 Correct 83 ms 35596 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 596 KB Output is correct
61 Correct 91 ms 8068 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 48 ms 11600 KB Output is correct
66 Correct 68 ms 8072 KB Output is correct
67 Correct 72 ms 8072 KB Output is correct
68 Correct 109 ms 8140 KB Output is correct
69 Correct 85 ms 35600 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 215 ms 45516 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 2120 KB Output is correct
13 Correct 224 ms 45580 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 76 ms 8068 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 65 ms 11660 KB Output is correct
21 Correct 178 ms 45572 KB Output is correct
22 Correct 256 ms 45504 KB Output is correct
23 Correct 181 ms 45528 KB Output is correct
24 Correct 183 ms 45588 KB Output is correct
25 Correct 69 ms 8072 KB Output is correct
26 Correct 64 ms 8064 KB Output is correct
27 Correct 217 ms 45568 KB Output is correct
28 Correct 177 ms 45612 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 2132 KB Output is correct
37 Correct 179 ms 45496 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 2112 KB Output is correct
41 Correct 176 ms 45596 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 72 ms 8068 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 53 ms 11668 KB Output is correct
50 Correct 184 ms 45584 KB Output is correct
51 Correct 184 ms 45572 KB Output is correct
52 Correct 187 ms 45580 KB Output is correct
53 Correct 83 ms 35656 KB Output is correct
54 Correct 69 ms 8140 KB Output is correct
55 Correct 182 ms 45592 KB Output is correct
56 Correct 186 ms 45556 KB Output is correct
57 Correct 83 ms 35596 KB Output is correct
58 Correct 1 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 52 ms 11656 KB Output is correct
62 Correct 192 ms 45568 KB Output is correct
63 Correct 185 ms 45516 KB Output is correct
64 Correct 186 ms 45552 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 60 ms 11592 KB Output is correct
67 Correct 170 ms 45568 KB Output is correct
68 Correct 225 ms 45544 KB Output is correct
69 Correct 182 ms 45536 KB Output is correct
70 Correct 1 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 44 ms 11656 KB Output is correct
74 Correct 175 ms 45572 KB Output is correct
75 Correct 202 ms 45480 KB Output is correct
76 Correct 194 ms 45500 KB Output is correct
77 Correct 192 ms 45516 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 596 KB Output is correct
81 Correct 91 ms 8068 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 48 ms 11600 KB Output is correct
86 Correct 68 ms 8072 KB Output is correct
87 Correct 72 ms 8072 KB Output is correct
88 Correct 109 ms 8140 KB Output is correct
89 Correct 85 ms 35600 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 6 ms 584 KB Output is correct
93 Correct 69 ms 8064 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 18 ms 2188 KB Output is correct
98 Correct 69 ms 8076 KB Output is correct
99 Correct 72 ms 8064 KB Output is correct
100 Correct 67 ms 8140 KB Output is correct
101 Correct 100 ms 8160 KB Output is correct
102 Correct 69 ms 8064 KB Output is correct
103 Correct 66 ms 8140 KB Output is correct
104 Correct 65 ms 8068 KB Output is correct
105 Correct 73 ms 8084 KB Output is correct