Submission #1078250

#TimeUsernameProblemLanguageResultExecution timeMemory
1078250mindiyakConnecting Supertrees (IOI20_supertrees)C++14
56 / 100
174 ms24188 KiB
#include "supertrees.h" #include <vector> #include <set> #include <iostream> using namespace std; vector<int> parent(1005,0); vector<int> parentg(1005,0); int get_parent(int a){ if(a == parent[a])return a; return get_parent(parent[a]); } int get_parentg(int a){ if(a == parentg[a])return a; return get_parentg(parentg[a]); } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n, vector<int>(n,0)); for(int i=0;i<n;i++)parent[i]=i; for(int i=0;i<n;i++)parentg[i]=i; 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){ if(get_parent(i) == get_parent(j))continue; answer[i][j] = 1; answer[j][i] = 1; parent[j] = get_parent(i); parentg[j] = parent[j]; } } } for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(p[i][j] == 2){ int a = get_parent(i), b = get_parent(j); if(a==b)continue; if(get_parentg(a) == get_parentg(b))continue; if(a>b)swap(a,b); parentg[get_parentg(b)] = get_parentg(a); } } } vector<set<int>> heads(1005); for(int i=0;i<n;i++){ heads[get_parentg(i)].insert(get_parent(i)); } for(int i=0;i<n;i++){ vector<int> temp; for(int a:heads[i])temp.push_back(a); int m = temp.size(); if(m < 2)continue; for(int j = 0;j<=temp.size();j++){ answer[temp[j%m]][temp[(j+1)%m]] = 1; answer[temp[(j+1)%m]][temp[j%m]] = 1; } } cerr << endl; for(int i=0;i<n;i++)cerr << get_parent(i) << " "; cerr << endl; for(int i=0;i<n;i++)cerr << get_parentg(i) << " "; cerr << endl; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ int a = get_parent(i), b = get_parent(j); int c = get_parentg(a), d = get_parentg(b); if(p[i][j] == 0){ if(a == b)return 0; if(c == d)return 0; } if(p[i][j] == 1){ if(a != b)return 0; } if(p[i][j] == 2){ if(heads[c].size() < 2)return 0; if(a == b)return 0; if(c != d)return 0; } } } build(answer); return 1; }

Compilation message (stderr)

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