Submission #977688

#TimeUsernameProblemLanguageResultExecution timeMemory
977688SmuggingSpunConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
169 ms18256 KiB
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; int construct(vector<vector<int>>p){ int n = p.size(); bool is_sub1 = true, is_sub2 = true, is_sub3 = false; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] != 1){ is_sub1 = false; } if(p[i][j] > 1){ is_sub2 = false; } if(p[i][j] != 0 && p[i][j] != 2){ is_sub3 = false; } } } if(is_sub1){ p = vector<vector<int>>(n, vector<int>(n, 0)); for(int i = 1; i < n; i++){ p[i][i - 1] = p[i - 1][i] = 1; } build(p); return 1; } if(is_sub2){ vector<int>par(n); iota(par.begin(), par.end(), 0); function<int(int)>find_set; find_set = [&] (int n){ return n == par[n] ? n : par[n] = find_set(par[n]); }; function<void(int, int)>merge = [&] (int a, int b){ par[find_set(a)] = find_set(b); }; vector<bool>vis(n, false); vector<vector<int>>edge(n); for(int i = 0; i < n; i++){ if(vis[i]){ for(int j = 0; j < n; j++){ if(i != j && int(find_set(i) == find_set(j)) != p[i][j]){ return 0; } } continue; } for(int j = 0; j < n; j++){ if(i != j && p[i][j] == 0 && find_set(i) == find_set(j)){ return 0; } if(p[i][j] == 1){ merge(i, j); vis[j] = true; } } } for(int i = 0; i < n; i++){ edge[find_set(i)].emplace_back(i); } p = vector<vector<int>>(n, vector<int>(n, 0)); for(int i = 0; i < n; i++){ for(int j = 1; j < edge[i].size(); j++){ p[edge[i][j]][edge[i][j - 1]] = p[edge[i][j - 1]][edge[i][j]] = 1; } } build(p); return 1; } if(is_sub3){ vector<int>par(n); iota(par.begin(), par.end(), 0); function<int(int)>find_set; find_set = [&] (int n){ return n == par[n] ? n : par[n] = find_set(par[n]); }; function<void(int, int)>merge = [&] (int a, int b){ par[find_set(a)] = find_set(b); }; vector<bool>vis(n, false); vector<vector<int>>edge(n); for(int i = 0; i < n; i++){ if(vis[i]){ for(int j = 0; j < n; j++){ if(i != j && int(find_set(i) == find_set(j)) != p[i][j]){ return 0; } } continue; } for(int j = 0; j < n; j++){ if(i != j && p[i][j] == 0 && find_set(i) == find_set(j)){ return 0; } if(p[i][j] == 1){ merge(i, j); vis[j] = true; } } } for(int i = 0; i < n; i++){ edge[find_set(i)].emplace_back(i); } p = vector<vector<int>>(n, vector<int>(n, 0)); for(int i = 0; i < n; i++){ if(edge[i].size() == 2){ return 0; } if(edge[i].size() > 2){ edge[i].emplace_back(edge[i][0]); for(int j = 1; j < edge[i].size(); j++){ p[edge[i][j]][edge[i][j - 1]] = p[edge[i][j - 1]][edge[i][j]] = 1; } } } build(p); return 1; } }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int j = 1; j < edge[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~
supertrees.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |     for(int j = 1; j < edge[i].size(); j++){
      |                    ~~^~~~~~~~~~~~~~~~
supertrees.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type]
  120 | }
      | ^
#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...