Submission #603554

#TimeUsernameProblemLanguageResultExecution timeMemory
603554CyberCowConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
218 ms30220 KiB
#include "supertrees.h" #include <vector> #include <queue> #include <unordered_set> using namespace std; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> ans(n); vector<int> a(n); vector<int> g[1005]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans[i].push_back(0); if (p[i][j]) { g[i].push_back(j); g[j].push_back(i); } } } int st1 = 0, st2 = 0, st0 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < p[i].size(); j++) { if (p[i][j] == 1) st1 = 1; else if (p[i][j] == 2) st2 = 1; else st0 = 1; } } if (st1 == 1 && st2 == 0 && st0 == 0) { for (int i = 1; i < n; i++) { ans[0][i] = 1; } for (int i = 1; i < n; i++) { ans[i][0] = 1; } } else if ((st0 == 1 || st1 == 1) && st2 == 0) { queue<int> q; for (int i = 0; i < n; i++) { if (a[i] == 0) { vector<int> va; q.push(i); while (!q.empty()) { int x = q.front(); va.push_back(x); a[x] = 1; q.pop(); for (int j = 0; j < g[x].size(); j++) { if (a[g[x][j]] == 0) { q.push(g[x][j]); a[g[x][j]] = 1; } } } for (int j = 0; j < va.size() - 1; j++) { ans[va[j]][va[j + 1]] = 1; ans[va[j + 1]][va[j]] = 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 0 && ans[i][j] != 0) return 0; } } } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int j = 0; j < p[i].size(); j++)
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |      for (int j = 0; j < g[x].size(); j++)
      |                      ~~^~~~~~~~~~~~~
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 j = 0; j < va.size() - 1; j++)
      |                     ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...