제출 #812577

#제출 시각아이디문제언어결과실행 시간메모리
812577KemalKConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
172 ms23164 KiB
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int pr[N]; int sz[N]; int get(int x){ if (pr[x] == x){ return x; } return (pr[x] = get(pr[x])); } void unit(int a, int b){ a = get(a); b = get(b); if (a != b){ if (sz[a] < sz[b]){ swap(a, b); } pr[b] = a; sz[a] += sz[b]; } } int construct(std::vector<std::vector<int>> p) { int n = p.size(); bool sub_task_1 = true; bool sub_task_2 = true; for (int i = 0; i < n; i++){ pr[i] = i; sz[i] = 1; } for (int i = 0; i < n; i++){ for (int j = 0; j < i + 1; j++){ if (i != j and p[i][j]){ unit(i, j); } } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] != 1){ sub_task_1 = false; } if (p[i][j] == 2 or p[i][j] == 3){ sub_task_2 = false; } } } std::vector<std::vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } if (n == 1){ //nothing to change } else if (sub_task_1){ // p[i][j] = 1 for (int i = 0; i < n - 1; i++){ answer[i][i + 1] = 1; answer[i + 1][i] = 1; } } else if(sub_task_2) { // p[i][j] = 1 or p[i][j] = 0 map <int, vector<int>> mp; for (int i = 0; i < n; i++){ int x = get(i); mp[x].push_back(i); } for (auto x: mp){ for (int i = 0; i < x.second.size() - 1; i++){ answer[x.second[i]][x.second[i + 1]] = 1; answer[x.second[i + 1]][x.second[i]] = 1; } } } build(answer); return 1; }

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

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