Submission #941237

# Submission time Handle Problem Language Result Execution time Memory
941237 2024-03-08T10:52:04 Z Numberz Connecting Supertrees (IOI20_supertrees) C++14
19 / 100
179 ms 22356 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));

  //checker
  vector<int> tracker(n, 0);
  
  vector<vector<int>> components;
  //checks if it is possible to build the bridges
  for (int i = 0; i < n; i++) {
    //checks if it should already be in a component
    bool search = true;
    
    for (int j = 0; j < components.size(); j++) {
      if (p[components[j][0]][i] == 2) {
        components[j].push_back(i);
        //cout << "prob first " << i << ' ' << j <<endl;
        //cout << "j: " << j << endl;
        tracker[i] = j;
        search = false;
        break;
      }
    }
    
    if (search) {
      components.push_back({i});
      //cout << "prob second " << i << ' ' << components.size()-1 <<endl;
      //cout << "comps: " << components.size() << endl;
      tracker[i] = components.size()-1;
    }
  }

  //check if wrong
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        if ((tracker[i] == tracker[j] && p[i][j] == 0) || (tracker[i] != tracker[j] && p[i][j] != 0)) {
          return 0;
        } 
      }
    }
  }
  //within each component, build a graph
  // size shoud be > 1
  for (auto comp : components) {
    if (comp.size() > 1) {
      if (comp.size() == 2) {
        return 0;
      }
      int k = comp.size();
      for (int i = 0; i < k-1; i++) {
        res[comp[i]][comp[i+1]] = 1;
        res[comp[i+1]][comp[i]] = 1;
      }
      res[comp[k-1]][comp[0]] = 1;
      res[comp[0]][comp[k-1]] = 1;
    }
  }
  
  build(res);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int j = 0; j < components.size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 9 ms 1116 KB Output is correct
9 Correct 159 ms 22040 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 1116 KB Output is correct
13 Correct 154 ms 22036 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 64 ms 12060 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 39 ms 5724 KB Output is correct
22 Correct 156 ms 22036 KB Output is correct
23 Correct 152 ms 22168 KB Output is correct
24 Correct 170 ms 22100 KB Output is correct
25 Correct 69 ms 12312 KB Output is correct
26 Correct 66 ms 12112 KB Output is correct
27 Correct 179 ms 22012 KB Output is correct
28 Correct 173 ms 22356 KB Output is correct
29 Correct 82 ms 12312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -