답안 #941232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941232 2024-03-08T10:50:07 Z Numberz 슈퍼트리 잇기 (IOI20_supertrees) C++14
96 / 100
571 ms 24412 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int construct(vector<std::vector<int>> p) {
  //subtask 1
  int n = p.size();
  vector<vector<int>> res(n, vector<int>(n, 0));

  //check if even possible
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (p[i][j] == 1) {
        for (int k = j; k < n; k++) {
          if (p[i][j] != 0 && p[i][k] != 0 && p[j][k] == 0) return 0;
        }
      } 
      else if (p[i][j] == 2) {
        for (int k = j; k < n; k++) {
          if (p[i][j] != 0 && p[i][k] != 0 && p[j][k] == 0) return 0;
        }
      }
    }
  }

  
  vector<vector<int>> trees;
  vector<bool> used(n, false);
  vector<int> roots;

  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    used[i] = true;
    trees.push_back({i});
    roots.push_back(i);
    for (int j = i+1; j < n; j++) {
      if (p[i][j] == 1) {
        used[j] = true;
        trees[trees.size()-1].push_back(j);
        res[i][j] = 1;
        res[j][i] = 1;
      }
    }
  }

  //we now build cycles out of the roots
  vector<vector<int>> cycles;
  vector<bool> used_cyc(roots.size(), false);
  for (int r = 0; r < roots.size(); r++) {
    if (used_cyc[r]) continue;
    used_cyc[r] = true;
    cycles.push_back({roots[r]});
    for (int j = r+1; j < roots.size(); j++) {
      if (p[roots[r]][roots[j]] == 2) {
        used_cyc[j] = true;
        cycles[cycles.size()-1].push_back(roots[j]);
      }
    }
  }

  for (auto cyc : cycles) {
    if (cyc.size() == 2) {
      return 0;
    }
    if (cyc.size() > 2) {
      int k = cyc.size();
      for (int i = 0; i < k-1; i++) {
        res[cyc[i]][cyc[i+1]] = 1;
        res[cyc[i+1]][cyc[i]] = 1;
      }
      res[cyc[k-1]][cyc[0]] = 1;
      res[cyc[0]][cyc[k-1]] = 1;
    }
  }
  
  build(res);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int r = 0; r < roots.size(); r++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:53:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int j = r+1; j < roots.size(); j++) {
      |                       ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 9 ms 1368 KB Output is correct
7 Correct 496 ms 24092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 9 ms 1368 KB Output is correct
7 Correct 496 ms 24092 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 160 ms 24412 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 65 ms 14160 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 42 ms 6336 KB Output is correct
21 Correct 210 ms 24344 KB Output is correct
22 Correct 154 ms 23972 KB Output is correct
23 Correct 571 ms 24208 KB Output is correct
24 Correct 156 ms 24148 KB Output is correct
25 Correct 107 ms 14076 KB Output is correct
26 Correct 58 ms 14076 KB Output is correct
27 Correct 563 ms 24060 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 153 ms 24148 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 9 ms 1372 KB Output is correct
13 Correct 409 ms 24148 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 63 ms 14160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 40 ms 6392 KB Output is correct
22 Correct 190 ms 24004 KB Output is correct
23 Correct 154 ms 24144 KB Output is correct
24 Correct 536 ms 24404 KB Output is correct
25 Correct 60 ms 14160 KB Output is correct
26 Correct 61 ms 14076 KB Output is correct
27 Correct 158 ms 24024 KB Output is correct
28 Correct 519 ms 24204 KB Output is correct
29 Correct 64 ms 14208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 41 ms 6224 KB Output is correct
5 Correct 216 ms 24232 KB Output is correct
6 Correct 155 ms 23968 KB Output is correct
7 Correct 567 ms 23948 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 40 ms 6232 KB Output is correct
10 Correct 191 ms 24188 KB Output is correct
11 Correct 159 ms 24208 KB Output is correct
12 Correct 513 ms 24212 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 42 ms 6228 KB Output is correct
17 Correct 186 ms 24184 KB Output is correct
18 Correct 187 ms 24036 KB Output is correct
19 Correct 169 ms 24236 KB Output is correct
20 Correct 153 ms 24056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 9 ms 1368 KB Output is correct
7 Correct 496 ms 24092 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 160 ms 24412 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 65 ms 14160 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 42 ms 6336 KB Output is correct
21 Correct 210 ms 24344 KB Output is correct
22 Correct 154 ms 23972 KB Output is correct
23 Correct 571 ms 24208 KB Output is correct
24 Correct 156 ms 24148 KB Output is correct
25 Correct 107 ms 14076 KB Output is correct
26 Correct 58 ms 14076 KB Output is correct
27 Correct 563 ms 24060 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 153 ms 24148 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 9 ms 1372 KB Output is correct
41 Correct 409 ms 24148 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 63 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 40 ms 6392 KB Output is correct
50 Correct 190 ms 24004 KB Output is correct
51 Correct 154 ms 24144 KB Output is correct
52 Correct 536 ms 24404 KB Output is correct
53 Correct 60 ms 14160 KB Output is correct
54 Correct 61 ms 14076 KB Output is correct
55 Correct 158 ms 24024 KB Output is correct
56 Correct 519 ms 24204 KB Output is correct
57 Correct 64 ms 14208 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 63 ms 14080 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 360 KB Output is correct
65 Correct 39 ms 6336 KB Output is correct
66 Correct 59 ms 14160 KB Output is correct
67 Correct 60 ms 14072 KB Output is correct
68 Correct 65 ms 14300 KB Output is correct
69 Correct 60 ms 14208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 9 ms 1368 KB Output is correct
7 Correct 496 ms 24092 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 160 ms 24412 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 65 ms 14160 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 42 ms 6336 KB Output is correct
21 Correct 210 ms 24344 KB Output is correct
22 Correct 154 ms 23972 KB Output is correct
23 Correct 571 ms 24208 KB Output is correct
24 Correct 156 ms 24148 KB Output is correct
25 Correct 107 ms 14076 KB Output is correct
26 Correct 58 ms 14076 KB Output is correct
27 Correct 563 ms 24060 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 153 ms 24148 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 9 ms 1372 KB Output is correct
41 Correct 409 ms 24148 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 63 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 40 ms 6392 KB Output is correct
50 Correct 190 ms 24004 KB Output is correct
51 Correct 154 ms 24144 KB Output is correct
52 Correct 536 ms 24404 KB Output is correct
53 Correct 60 ms 14160 KB Output is correct
54 Correct 61 ms 14076 KB Output is correct
55 Correct 158 ms 24024 KB Output is correct
56 Correct 519 ms 24204 KB Output is correct
57 Correct 64 ms 14208 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 41 ms 6224 KB Output is correct
62 Correct 216 ms 24232 KB Output is correct
63 Correct 155 ms 23968 KB Output is correct
64 Correct 567 ms 23948 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 40 ms 6232 KB Output is correct
67 Correct 191 ms 24188 KB Output is correct
68 Correct 159 ms 24208 KB Output is correct
69 Correct 513 ms 24212 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 436 KB Output is correct
73 Correct 42 ms 6228 KB Output is correct
74 Correct 186 ms 24184 KB Output is correct
75 Correct 187 ms 24036 KB Output is correct
76 Correct 169 ms 24236 KB Output is correct
77 Correct 153 ms 24056 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 63 ms 14080 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 360 KB Output is correct
85 Correct 39 ms 6336 KB Output is correct
86 Correct 59 ms 14160 KB Output is correct
87 Correct 60 ms 14072 KB Output is correct
88 Correct 65 ms 14300 KB Output is correct
89 Correct 60 ms 14208 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 436 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 62 ms 14160 KB Output is correct
94 Incorrect 1 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -