Submission #603544

#TimeUsernameProblemLanguageResultExecution timeMemory
603544MherConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
198 ms26072 KiB
#include <bits/stdc++.h> #include "supertrees.h" #include <vector> using namespace std; int n; vector<vector<int>> a; vector<int> col; vector<vector<int>> r; vector<int> gr; vector<vector<int>> c; vector<vector<int>> ans; bool check() { for (int i = 0; i < r.size(); i++) { for (int j = 0; j < r[i].size(); j++) { for (int k = 0; k < j; k++) { if (a[r[i][j]][r[i][k]] != 1) return false; } } } return true; } void conect(int v, int u) { ans[v][u] = 1; ans[u][v] = 1; } void dfs(int v) { for (int i = 0; i < n; i++) { if (i == v) continue; if (a[v][i] == 1 && col[i] == -1) { r[col[v]].push_back(i); col[i] = col[v]; dfs(i); } } } int construct(vector<vector<int>> p) { n = p.size(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 3) return 0; } } a = p; ans = vector<vector<int>>(n, vector<int>(n, 0)); int cnt = 0; col = vector<int>(n, -1); for (int i = 0; i < n; i++) { if (col[i] == -1) { r.push_back(vector<int>(1, i)); col[i] = cnt++; dfs(i); } } if (!check()) return 0; for (int i = 0; i < r.size(); i++) { for (int j = 0; j < r[i].size() - 1; j++) { conect(r[i][j], r[i][j + 1]); } } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'bool check()':
supertrees.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < r.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:19:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for (int j = 0; j < r[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 0; i < r.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int j = 0; j < r[i].size() - 1; 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...