답안 #667216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667216 2022-11-30T18:42:21 Z atigun 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
214 ms 24032 KB
#include<bits/stdc++.h>
#include"supertrees.h"
 
using namespace std;
typedef long long ll;
 
struct dsu{
  vector<int> parent, size;
  int N;
  void assign(int dsusize){
    N = dsusize;
    parent.assign(N, 0);
    iota(parent.begin(), parent.end(), 0);
    size.assign(N, 1);
  }
  int find(int v){
    return parent[v] = (parent[v] == v ? v : find(parent[v]));
  }
  void merge(int v, int u){
    if(find(v) == find(u))
      return;
    if(size[find(v)] < size[find(u)])
      swap(u, v);
    size[find(v)]+= size[find(u)];
    parent[find(u)] = parent[find(v)];
  }
  bool is_same(int v, int u){
    return (find(v) == find(u));
  }
};
 
dsu DSU;
vector<vector<int>> ans;
 
void make_edge(int x, int y){
  ans[x][y] = ans[y][x] = 1;
}
 
int construct(vector<vector<int>> p){
  int n = p.size();
  ans.assign(n, vector<int>(n));
  DSU.assign(n);
  bool ok = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(p[i][j])
        DSU.merge(i, j);
      if(p[i][j] == 3)
        return 0;
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(DSU.is_same(i, j) != (p[i][j] != 0))
        return 0;
    }
  }
  vector<vector<int>> groups(n);
  for(int i = 0; i < n; i++)
    groups[DSU.find(i)].push_back(i);
  for(vector<int>& G : groups){
    if(G.size() <= 1)
      continue;
    vector<int> mid, other;
    mid.reserve(n);
    for(int x : G){
      bool alltwo = true;
      for(int y : G)
        alltwo&= (x == y || p[x][y] == 2);
      if(alltwo)
        mid.push_back(x);
      else
        other.push_back(x);
    }
    vector<bool> vis(n);
    for(int x : other){
      if(vis[x])
        continue;
      vector<int> side = {x};
      mid.push_back(x);
      vis[x] = true;
      for(int y : other){
        if(p[x][y] == 1 && x != y){
          if(vis[y])
            return 0;
          side.push_back(y);
          vis[y] = 1;
        }
      }
      for(int k1 : side){
        for(int k2 : side){
          if(p[k1][k2] != 1)
            return 0;
        }
      }
      for(int i = 1; i < side.size(); i++)
        make_edge(side[i], side[i-1]);
    }
    if(mid.size() == 2)
      return 0;
    if(mid.size() > 1)
      for(int i = 0; i < (int) (mid.size()); i++)
        make_edge(mid[i], mid[(i+1)%((int) (mid.size()))]);
  }
  build(ans); 
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:96:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |       for(int i = 1; i < side.size(); i++)
      |                      ~~^~~~~~~~~~~~~
supertrees.cpp:43:8: warning: unused variable 'ok' [-Wunused-variable]
   43 |   bool ok = 1;
      |        ^~
# 결과 실행 시간 메모리 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 8 ms 1128 KB Output is correct
7 Correct 179 ms 22032 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 1128 KB Output is correct
7 Correct 179 ms 22032 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 182 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 99 ms 12032 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5688 KB Output is correct
21 Correct 175 ms 22092 KB Output is correct
22 Correct 173 ms 22096 KB Output is correct
23 Correct 182 ms 22032 KB Output is correct
24 Correct 161 ms 22016 KB Output is correct
25 Correct 65 ms 12032 KB Output is correct
26 Correct 64 ms 12036 KB Output is correct
27 Correct 187 ms 21964 KB Output is correct
28 Correct 168 ms 22052 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 7 ms 1108 KB Output is correct
9 Correct 158 ms 22032 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 1124 KB Output is correct
13 Correct 198 ms 22124 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 724 KB Output is correct
17 Correct 81 ms 12052 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 5708 KB Output is correct
22 Correct 183 ms 22044 KB Output is correct
23 Correct 178 ms 22020 KB Output is correct
24 Correct 183 ms 22032 KB Output is correct
25 Correct 67 ms 12164 KB Output is correct
26 Correct 69 ms 12048 KB Output is correct
27 Correct 174 ms 22024 KB Output is correct
28 Correct 191 ms 22024 KB Output is correct
29 Correct 90 ms 12164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 5764 KB Output is correct
5 Correct 178 ms 22068 KB Output is correct
6 Correct 175 ms 22088 KB Output is correct
7 Correct 180 ms 22064 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 51 ms 5712 KB Output is correct
10 Correct 167 ms 22032 KB Output is correct
11 Correct 170 ms 22024 KB Output is correct
12 Correct 214 ms 21988 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 5712 KB Output is correct
17 Correct 183 ms 24016 KB Output is correct
18 Correct 168 ms 23944 KB Output is correct
19 Correct 179 ms 23936 KB Output is correct
20 Correct 173 ms 24032 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 1128 KB Output is correct
7 Correct 179 ms 22032 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 182 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 99 ms 12032 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5688 KB Output is correct
21 Correct 175 ms 22092 KB Output is correct
22 Correct 173 ms 22096 KB Output is correct
23 Correct 182 ms 22032 KB Output is correct
24 Correct 161 ms 22016 KB Output is correct
25 Correct 65 ms 12032 KB Output is correct
26 Correct 64 ms 12036 KB Output is correct
27 Correct 187 ms 21964 KB Output is correct
28 Correct 168 ms 22052 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 1 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 7 ms 1108 KB Output is correct
37 Correct 158 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1124 KB Output is correct
41 Correct 198 ms 22124 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 81 ms 12052 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 5708 KB Output is correct
50 Correct 183 ms 22044 KB Output is correct
51 Correct 178 ms 22020 KB Output is correct
52 Correct 183 ms 22032 KB Output is correct
53 Correct 67 ms 12164 KB Output is correct
54 Correct 69 ms 12048 KB Output is correct
55 Correct 174 ms 22024 KB Output is correct
56 Correct 191 ms 22024 KB Output is correct
57 Correct 90 ms 12164 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 80 ms 12052 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 5756 KB Output is correct
66 Correct 70 ms 14088 KB Output is correct
67 Correct 69 ms 14000 KB Output is correct
68 Correct 69 ms 14088 KB Output is correct
69 Correct 84 ms 14104 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 1128 KB Output is correct
7 Correct 179 ms 22032 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 182 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 99 ms 12032 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5688 KB Output is correct
21 Correct 175 ms 22092 KB Output is correct
22 Correct 173 ms 22096 KB Output is correct
23 Correct 182 ms 22032 KB Output is correct
24 Correct 161 ms 22016 KB Output is correct
25 Correct 65 ms 12032 KB Output is correct
26 Correct 64 ms 12036 KB Output is correct
27 Correct 187 ms 21964 KB Output is correct
28 Correct 168 ms 22052 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 1 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 7 ms 1108 KB Output is correct
37 Correct 158 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1124 KB Output is correct
41 Correct 198 ms 22124 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 81 ms 12052 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 5708 KB Output is correct
50 Correct 183 ms 22044 KB Output is correct
51 Correct 178 ms 22020 KB Output is correct
52 Correct 183 ms 22032 KB Output is correct
53 Correct 67 ms 12164 KB Output is correct
54 Correct 69 ms 12048 KB Output is correct
55 Correct 174 ms 22024 KB Output is correct
56 Correct 191 ms 22024 KB Output is correct
57 Correct 90 ms 12164 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 42 ms 5764 KB Output is correct
62 Correct 178 ms 22068 KB Output is correct
63 Correct 175 ms 22088 KB Output is correct
64 Correct 180 ms 22064 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 51 ms 5712 KB Output is correct
67 Correct 167 ms 22032 KB Output is correct
68 Correct 170 ms 22024 KB Output is correct
69 Correct 214 ms 21988 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 5712 KB Output is correct
74 Correct 183 ms 24016 KB Output is correct
75 Correct 168 ms 23944 KB Output is correct
76 Correct 179 ms 23936 KB Output is correct
77 Correct 173 ms 24032 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 80 ms 12052 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 5756 KB Output is correct
86 Correct 70 ms 14088 KB Output is correct
87 Correct 69 ms 14000 KB Output is correct
88 Correct 69 ms 14088 KB Output is correct
89 Correct 84 ms 14104 KB Output is correct
90 Correct 1 ms 216 KB Output is correct
91 Correct 0 ms 216 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 72 ms 14072 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 300 KB Output is correct
97 Correct 18 ms 3716 KB Output is correct
98 Correct 66 ms 14028 KB Output is correct
99 Correct 67 ms 14084 KB Output is correct
100 Correct 65 ms 14068 KB Output is correct
101 Correct 68 ms 14032 KB Output is correct
102 Correct 64 ms 14028 KB Output is correct
103 Correct 65 ms 13992 KB Output is correct
104 Correct 64 ms 14056 KB Output is correct
105 Correct 94 ms 14068 KB Output is correct