Submission #823616

#TimeUsernameProblemLanguageResultExecution timeMemory
823616GusterGoose27Connecting Supertrees (IOI20_supertrees)C++17
100 / 100
198 ms24068 KiB
#include "supertrees.h" #include <bits/stdc++.h> const int MAXN = 1e3+5; using namespace std; int n; int uf[MAXN]; int find(int i) { return uf[i] == i ? i : uf[i] = find(uf[i]); } void merge(int a, int b) { a = find(a); b = find(b); assert(a != b); uf[a] = b; } bool vis[MAXN]; int construct(vector<vector<int>> p) { n = p.size(); iota(uf, uf+n, 0); vector<vector<int>> answer(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 3) return 0; if (find(i) != find(j) && p[i][j] == 1) { answer[i][j] = answer[j][i] = 1; merge(i, j); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 1 && find(i) != find(j)) return 0; if (p[i][j] != 1 && find(i) == find(j)) return 0; } } // all 1 connections are dealt with for (int i = 0; i < n; i++) { vector<int> vals; int cur = find(i); if (vis[cur]) continue; do { if (vals.size()) merge(vals.back(), cur); vals.push_back(cur); vis[cur] = 1; bool f = 0; for (int j = 0; j < n; j++) { if (uf[j] != j || vis[j] || j == find(i)) continue; if (p[cur][j] == 2) { f = 1; cur = j; break; } } if (!f) cur = find(i); } while (cur != find(i)); if (vals.size() == 2) return 0; if (vals.size() > 1) { for (int j = 0; j < vals.size(); j++) { answer[vals[j]][vals[(j+1)%vals.size()]] = answer[vals[(j+1)%vals.size()]][vals[j]] = 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] >= 1 && find(i) != find(j)) return 0; if (p[i][j] == 0 && find(i) == find(j)) return 0; } } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:22: 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 = 0; j < vals.size(); 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...