제출 #405064

#제출 시각아이디문제언어결과실행 시간메모리
405064ly20슈퍼트리 잇기 (IOI20_supertrees)C++17
21 / 100
245 ms30148 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1123; int comp[MAXN]; vector <int> grafo[MAXN]; int marc[MAXN]; int cmp; //vector <int> grafo2[MAXN]; void dfs(int v) { marc[v] = 1; comp[v] = cmp; for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(marc[viz] == 1) continue; dfs(viz); } } int resp[MAXN][MAXN]; int cic[MAXN][MAXN]; int rep[MAXN]; int cm2[MAXN], cmp2; int marc2[MAXN]; vector <int> ln[MAXN]; vector <vector <int> > answer; //vector <int> temp; void dfs2(int v) { marc2[v] = 1; cm2[v] = cmp2; for(int i = 0; i < cmp; i++) { if(marc[i] == 1) continue; if(cic[v][i] == 1) dfs2(i); } } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer; for(int i = 0; i < n; i++) { comp[i] = i; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(p[i][j] == 1) { grafo[i].push_back(j); } } } for(int i = 0; i < n; i++) { if(marc[i] == 0) { dfs(i); cmp++; } } for(int i = 0; i < cmp; i++) { for(int j = 0; j < n; j++) if(comp[j] == i) ln[i].push_back(j); int m = ln[i].size(); for(int j = 0; j < m; j++) { int cur = ln[i][j]; for(int k = j + 1; k < m; k++) { int tst = ln[i][k]; if(p[cur][tst] != 1) { return 0; } } } for(int j = 0; j < m - 1; j++) { int pr = j + 1; resp[ln[i][j]][ln[i][pr]] = 1; resp[ln[i][pr]][ln[i][j]] = 1; } rep[i] = ln[i][0]; } for(int i = 0; i < cmp; i++) { for(int j = i + 1; j < cmp; j++) { int bs = p[rep[i]][rep[j]]; for(int k = 0; k < ln[i].size(); k++) { for(int l = 0; l < ln[j].size(); l++) { if(p[ln[i][k]][ln[j][l]] != bs) bs = -1; } } if(bs == 1) { cic[i][j] = 1; cic[j][i] = 1; } else if(bs == -1) return 0; } } for(int i = 0; i < cmp; i++) { if(marc2[i] == 0) { dfs2(i); cmp2++; } } for(int i = 0; i < cmp2; i++) { vector <int> temp; for(int j = 0; j < cmp; j++) if(cm2[j] == i) temp.push_back(j); int m = temp.size(); for(int j = 0; j < m; j++) { for(int k = j + 1; k < m; k++) { if(cic[temp[j]][temp[k]] == 0) return 0; } } if(temp.size() == 1) continue; for(int j = 0; j < m; j++) { int pr = (j + 1) % m; resp[rep[temp[pr]]][rep[temp[j]]] = 1; resp[rep[temp[j]]][rep[temp[pr]]] = 1; } } for (int i = 0; i < n; i++) { vector<int> row; for(int j = 0; j < n; j++) { row.push_back(resp[i][j]); } answer.push_back(row); } build(answer); return 1; }

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

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:76:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for(int k = 0; k < ln[i].size(); k++) {
      |                            ~~^~~~~~~~~~~~~~
supertrees.cpp:77:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |                 for(int l = 0; l < ln[j].size(); l++) {
      |                                ~~^~~~~~~~~~~~~~
#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...