Submission #838647

#TimeUsernameProblemLanguageResultExecution timeMemory
838647SoulKnightConnecting Supertrees (IOI20_supertrees)C++17
19 / 100
174 ms22096 KiB
#include "supertrees.h" #include <vector> #include <iostream> #include <numeric> #include <cstring> using namespace std; #define ll long long #define ln '\n' const int N = 1000 + 5; int par[N], who[N]; vector<int> com[N]; int find(int u){return ((u == par[u])? u: par[u]=find(par[u]));} int construct(std::vector<std::vector<int>> p) { int n = p.size(); std::vector<std::vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } iota(par, par+n, 0); memset(who, -1, sizeof(who)); for (int i = 0; i < n; i++){ for (int j = i+1; j < n; j++){ if (p[i][j] == 0) continue; par[find(i)] = find(j); } } // for (int i = 0; i < n; i++){ // for (int j = i+1; j < n; j++){ // if (p[i][j] == 0 && find(i) == find(j)) return 0; // } // } for (int i = 0; i < n; i++){ com[find(i)].push_back(i); } for (int i = 0; i < n; i++){ if (com[i].size() <= 1) continue; vector<int> cycle; for (auto& v: com[i]){ for (auto& j: com[i]){ if (v == j) continue; if (p[v][j] == 2) continue; if (p[j][v] == 0) return 0; if (who[j] != who[v]) return 0; if (who[j] == -1) who[j] = v; answer[j][v] = answer[v][j] = 1; } if (who[v] == -1) {who[v] = v; cycle.push_back(v);} } if (cycle.size() <= 2) return 0; for (int i = 1; i < cycle.size(); i++){ answer[cycle[i-1]][cycle[i]] = answer[cycle[i]][cycle[i-1]] = 1; } answer[cycle.front()][cycle.back()] = answer[cycle.back()][cycle.front()] = 1; } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 1; i < cycle.size(); i++){
      |                   ~~^~~~~~~~~~~~~~
#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...