Submission #1073411

#TimeUsernameProblemLanguageResultExecution timeMemory
1073411blushingecchigirlConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
184 ms24184 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back struct dsu { vector<int> parent, rank; int size; dsu(int sz) { size = sz; rank.assign(size, 1); parent.resize(size); for(int i = 0; i<size; i++) parent[i] = i; } int search(int v) { if(v == parent[v]) return v; return parent[v] = search(parent[v]); } void connect(int v, int u) { v = search(v); u = search(u); if(v == u) return; if(rank[v]>=rank[u]) parent[u] = v; else parent[v] = u; if(rank[v] == rank[u]) rank[v]++; return; } }; void build(std::vector<std::vector<int>> b); int construct(std::vector<std::vector<int>> p) { int n = p.size(); bool ctr = 1; vector<vector<int>> b(n); for(int i = 0; i<n; i++) b[i].resize(n, 0); vector<int> a[n]; dsu d = dsu(n); for(int i = 0; i<n; i++) { for(int j = 0; j<n; j++) { if(p[i][j]) d.connect(i, j); } } for(int i = 0; i<n; i++) { a[d.search(i)].pb(i); } for(int i = 0; i<n; i++) { if(a[i].size()<=1) continue; int pth = p[a[i][0]][a[i][1]]; for(int ii:a[i]) { for(int j:a[i]) { if(ii == j) continue; if(p[ii][j] != pth) ctr = 0; } } for(int ii = 1; ii<a[i].size(); ii++) { b[a[i][ii]][a[i][ii-1]] = b[a[i][ii-1]][a[i][ii]] = 1; } if(pth == 2) b[a[i][0]][a[i].back()] = b[a[i].back()][a[i][0]] = 1; if(pth == 2 && a[i].size() == 2) ctr = 0; } if(ctr) build(b); return ctr; }

Compilation message (stderr)

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