Submission #880439

# Submission time Handle Problem Language Result Execution time Memory
880439 2023-11-29T12:32:11 Z AkibAzmain Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#include <vector>

int construct(std::vector<std::vector<int>> p) {
  int n = p.size();
  std::vector<std::vector<int>> ans (n, vector < int > (n));
  vector < pair < int, int > > dsu (n);
  for (int i = 0; i < n; ++i) dsu[i].first = -1, dsu[i].second = 1;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      if (p[i][j] == 2)
        {
          int ci = i, cj = j;
          while (dsu[ci].first != -1) ci = dsu[ci].first;
          while (dsu[cj].first != -1) cj = dsu[cj].first;
          if (ci != cj)
            {
              if (dsu[ci].second < dsu[cj].second) swap (ci, cj);
              dsu[cj].first = ci;
              dsu[ci].second += dsu[cj].second;
            }
        }
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      if (p[i][j] == 0)
        {
          int ci = i, cj = j;
          while (dsu[ci].first != -1) ci = dsu[ci].first;
          while (dsu[cj].first != -1) cj = dsu[cj].first;
          if (ci == cj) return 0;
        }
  map < int, vector < int > > s;
  for (int i = 0; i < n; ++i)
    {
      int ci = i;
      while (dsu[ci].first != -1) ci = dsu[ci].first;
      s[ci].push_back (i);
    }
  for (auto &[y, ss] : s)
    {
      for (int i = 1; i < ss.size (); ++i) ans[ss[i]][ss[i - 1]] = ans[ss[i - 1]][ss[i]] = 1;
      if (ss.size () > 1) ans[ss.front ()][ss.back ()] = ans[ss.back ()][ss.front ()] = 1;
    }
  build (ans);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for (int i = 1; i < ss.size (); ++i) ans[ss[i]][ss[i - 1]] = ans[ss[i - 1]][ss[i]] = 1;
      |                       ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 412 KB Output is correct
3 Incorrect 1 ms 344 KB Too few ways to get from 1 to 2, should be 1 found 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -