Submission #576697

#TimeUsernameProblemLanguageResultExecution timeMemory
576697VanillaConnecting Supertrees (IOI20_supertrees)C++17
46 / 100
370 ms22204 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; const int maxn = 1002; int d[maxn]; int dad (int x) { return d[x] = (x == d[x] ? x: dad(d[x])); } void merge (int a, int b){ a = dad(a); b = dad(b); d[b] = a; } int construct(vector<vector<int>> p) { int n = p.size(); vector <vector <int> > b (n, vector <int> (n, 0)); for (int i = 0; i < n; i++){ d[i] = i; } for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ for (int k = j + 1; k < n; k++){ if (p[i][j] == 1 && p[j][k] == 1 && p[i][k] != 1) return 0; } } } for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ if (p[i][j] == 3) return 0; if (p[i][j] == 1 && dad(i) != dad(j)) { b[i][j] = b[j][i] = 1; merge(i,j); } } } for (int i = 0; i < n; i++){ vector <int> v; v.push_back(dad(i)); for (int j = i + 1; j < n; j++){ if (p[i][j] == 2 && dad(i) != dad(j)) { v.push_back(dad(j)); merge(i, j); } } if (v.size() == 2) return 0; if (v.size() > 1) for (int i = 0; i < v.size(); i++){ int p1 = v[i], p2 = v[(i + 1) % v.size()]; b[p1][p2] = b[p2][p1] = 1; } } build(b); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |    for (int i = 0; i < v.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...