Submission #300668

# Submission time Handle Problem Language Result Execution time Memory
300668 2020-09-17T11:32:12 Z abeker Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
273 ms 30428 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
 
class EquivRelation {
  int n;
  vector <bool> vis;
  vector <vector <int>> adj;
public:
  EquivRelation(int _n) {
    n = _n;
    adj.resize(n);
    vis.resize(n);
  }
  void addEdge(int u, int v) {
    adj[u].push_back(v);
  }
  void dfs(int x, vector <int> &comp) {
    vis[x] = true;
    comp.push_back(x);
    for (auto it : adj[x])
      if (!vis[it])
        dfs(it, comp);
  }
  bool isClique(const vector <int> &v) const {
    for (auto it : v)
      if (adj[it].size() != v.size())
        return false;
    return true;
  }
  vector <vector <int>> getClasses() {
    vector <vector <int>> res;
    for (int i = 0; i < n; i++) 
      if (!vis[i]) {
        vector <int> curr;
        dfs(i, curr);
        if (!isClique(curr))
          return vector <vector <int>> ();
        res.push_back(curr);
      }
    return res;
  }
};
 
int construct(vector <vector <int>> p) {
  int N = p.size();
  EquivRelation conn(N), one(N);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      if (p[i][j])
        conn.addEdge(i, j);
      if (p[i][j] == 1)
        one.addEdge(i, j);  
      else if (p[i][j] == 3)
        return 0;
    }
  vector <vector <int>> comps = conn.getClasses();
  vector <vector <int>> groups = one.getClasses();
  if (comps.empty() || groups.empty())
    return 0;
  int sz = comps.size();
  vector <int> idx(N);
  for (int i = 0; i < sz; i++)
    for (auto it : comps[i])
      idx[it] = i;
  vector <vector <int>> b(N, vector <int> (N, 0));
  auto make_edge = [&](int u, int v) {
    b[u][v] = b[v][u] = 1;
  };
  vector <vector <int>> cycle(sz);
  for (auto it : groups) {
    for (int i = 1; i < it.size(); i++)
      make_edge(it[0], it[i]);
    cycle[idx[it[0]]].push_back(it[0]);
  }
  for (auto it : cycle)
    if (it.size() > 1)
      for (int i = 0; i < it.size(); i++)
        make_edge(it[i], it[(i + 1) % it.size()]);
  build(b);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 1; i < it.size(); i++)
      |                     ~~^~~~~~~~~~~
supertrees.cpp:78:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |       for (int i = 0; i < it.size(); i++)
      |                       ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 266 ms 30428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 266 ms 30428 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 242 ms 22392 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 132 ms 13336 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 68 ms 5980 KB Output is correct
21 Correct 246 ms 23288 KB Output is correct
22 Correct 241 ms 22264 KB Output is correct
23 Correct 264 ms 26232 KB Output is correct
24 Correct 240 ms 22392 KB Output is correct
25 Correct 102 ms 9336 KB Output is correct
26 Correct 94 ms 8312 KB Output is correct
27 Correct 265 ms 28280 KB Output is correct
28 Correct 240 ms 22392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 60 ms 5880 KB Output is correct
5 Correct 238 ms 23160 KB Output is correct
6 Correct 238 ms 22392 KB Output is correct
7 Correct 260 ms 26360 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 66 ms 6008 KB Output is correct
10 Correct 237 ms 22776 KB Output is correct
11 Correct 235 ms 22392 KB Output is correct
12 Correct 273 ms 25464 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 63 ms 6008 KB Output is correct
17 Correct 250 ms 22776 KB Output is correct
18 Correct 240 ms 22776 KB Output is correct
19 Correct 239 ms 22648 KB Output is correct
20 Correct 234 ms 22392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 266 ms 30428 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 242 ms 22392 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 132 ms 13336 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 68 ms 5980 KB Output is correct
21 Correct 246 ms 23288 KB Output is correct
22 Correct 241 ms 22264 KB Output is correct
23 Correct 264 ms 26232 KB Output is correct
24 Correct 240 ms 22392 KB Output is correct
25 Correct 102 ms 9336 KB Output is correct
26 Correct 94 ms 8312 KB Output is correct
27 Correct 265 ms 28280 KB Output is correct
28 Correct 240 ms 22392 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1664 KB Output is correct
7 Correct 266 ms 30428 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 242 ms 22392 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 132 ms 13336 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 68 ms 5980 KB Output is correct
21 Correct 246 ms 23288 KB Output is correct
22 Correct 241 ms 22264 KB Output is correct
23 Correct 264 ms 26232 KB Output is correct
24 Correct 240 ms 22392 KB Output is correct
25 Correct 102 ms 9336 KB Output is correct
26 Correct 94 ms 8312 KB Output is correct
27 Correct 265 ms 28280 KB Output is correct
28 Correct 240 ms 22392 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -