Submission #554379

#TimeUsernameProblemLanguageResultExecution timeMemory
554379n0sk1llConnecting Supertrees (IOI20_supertrees)C++14
100 / 100
231 ms24268 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int up[1003]; vector<int> chain[1003]; vector<int> head; vector<int> kompofheads[1003]; int Up(int x) { if (up[x]<0) return x; return up[x]=Up(up[x]); } void dsu(int a, int b) { a=Up(a),b=Up(b); if (a==b) return; up[a]=b; } vector<vector<int>> ans; void add(int i, int j) { ans[i][j]=1,ans[j][i]=1; } int construct(vector<vector<int>> p) { int n = p.size(); for (int i=0;i<n;i++) { vector<int> pom(n,0); ans.push_back(pom); } for (int i=0;i<n;i++) if (p[i][i]!=1) return 0; for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (p[i][j]==3) return 0; for (int i=0;i<n;i++) up[i]=-1; for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (p[i][j]==1) dsu(i,j); for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (Up(i)==Up(j) && p[i][j]!=1) return 0; for (int i=0;i<n;i++) chain[Up(i)].push_back(i); for (int i=0;i<n;i++) if (up[i]<0) head.push_back(i); for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (p[i][j]) dsu(i,j); for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (Up(i)==Up(j) && !p[i][j]) return 0; for (int i=0;i<head.size();i++) kompofheads[Up(head[i])].push_back(head[i]); for (int i=0;i<n;i++) { if (kompofheads[i].size()==2) return 0; if (kompofheads[i].size()>2) { for (int j=1;j<kompofheads[i].size();j++) add(kompofheads[i][j-1],kompofheads[i][j]); add(kompofheads[i].front(),kompofheads[i].back()); } } for (int i=0;i<n;i++) for (int j=1;j<chain[i].size();j++) add(chain[i][j-1],chain[i][j]); build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i=0;i<head.size();i++)
      |                  ~^~~~~~~~~~~~
supertrees.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for (int j=1;j<kompofheads[i].size();j++) add(kompofheads[i][j-1],kompofheads[i][j]);
      |                          ~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j=1;j<chain[i].size();j++)
      |                      ~^~~~~~~~~~~~~~~~
supertrees.cpp:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |     for (int i=0;i<n;i++)
      |     ^~~
supertrees.cpp:85:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  build(ans);
      |  ^~~~~
#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...