Submission #769103

#TimeUsernameProblemLanguageResultExecution timeMemory
769103t6twotwoConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
165 ms22076 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int construct(std::vector<std::vector<int>> a) { int N = a.size(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (a[i][j] == 3) { return 0; } } } vector<bool> vis(N); auto bfs = [&](int s, int t) { vector<int> v; queue<int> q; q.push(s); vis[s] = 1; while (!q.empty()) { int x = q.front(); q.pop(); v.push_back(x); for (int y = 0; y < N; y++) { if (!vis[y] && a[x][y] == t) { vis[y] = 1; q.push(y); } } } return v; }; vector ans(N, vector<int>(N)); for (int i = 0; i < N; i++) { if (vis[i]) { continue; } auto v = bfs(i, 1); for (int x : v) { for (int j = 0; j < N; j++) { if (a[x][j] != a[v[0]][j]) { return 0; } } } for (int j = 1; j < v.size(); j++) { ans[i][v[j]] = ans[v[j]][i] = 1; } vis[i] = 0; } for (int i = 0; i < N; i++) { if (vis[i]) { continue; } auto v = bfs(i, 2); if (v.size() == 1) { continue; } if (v.size() == 2) { return 0; } for (int j = 0; j < v.size(); j++) { for (int k = j + 1; k < v.size(); k++) { if (!a[v[j]][v[k]]) { return 0; } } } for (int j = 0; j < v.size(); j++) { int x = v[j]; int y = v[j + 1 == v.size() ? 0 : j + 1]; ans[x][y] = ans[y][x] = 1; } } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int j = 1; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int j = 0; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:62:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for (int k = j + 1; k < v.size(); k++) {
      |                                 ~~^~~~~~~~~~
supertrees.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int j = 0; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:70:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             int y = v[j + 1 == v.size() ? 0 : j + 1];
      |                       ~~~~~~^~~~~~~~~~~
#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...