제출 #373225

#제출 시각아이디문제언어결과실행 시간메모리
373225Matteo_Verz슈퍼트리 잇기 (IOI20_supertrees)C++17
46 / 100
939 ms24300 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> answer; vector <int> viz; bool ok = true; void Solve_Component(int node, vector <vector <int>> p, int comp) { int n = p.size(); viz[node] = comp; for(int i = 0; i < n; i++) if(p[node][i] > 0) viz[i] = comp; // mark each node as part of the component vector <bool> isroot(n, false); for(int i = 0; i < n; i++) if(viz[i] == comp) isroot[i] = true; // we consider each node as the "root" vector <int> roots; for(int i = 0; i < n; i++) { // we go through each node if(isroot[i] == true) { roots.push_back(i); for(int j = 0; j < n; j++) { if(i == j) continue; if(p[i][j] == 1) { // if there is only 1 path from i to j => i is parent of j answer[i][j] = answer[j][i] = 1; isroot[j] = false; } } } } if(roots.size() == 1) return; // it's fine, we only have a tree if(roots.size() == 2) { // we have a cycle of length 2 => impossible ok = false; return; } for(int i = 0; i < roots.size() - 1; i++) answer[roots[i]][roots[i + 1]] = answer[roots[i + 1]][roots[i]] = 1; // we connect the roots answer[roots[0]][roots.back()] = answer[roots.back()][roots[0]] = 1; } int construct(vector<vector<int>> p) { int n = p.size(); answer.resize(n); for(int i = 0; i < n; i++) answer[i].resize(n); // last subtask, p[i][j] == 3 for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) if(p[i][j] > 2) return 0; } viz.resize(n); int cc(0); for(int i = 0; i < n; i++) if(viz[i] == 0) Solve_Component(i, p, ++cc); // solve for each component if(ok == false) return 0; build(answer); return 1; }

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'void Solve_Component(int, std::vector<std::vector<int> >, int)':
supertrees.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i = 0; i < roots.size() - 1; 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...