제출 #461233

#제출 시각아이디문제언어결과실행 시간메모리
461233armand슈퍼트리 잇기 (IOI20_supertrees)C++14
11 / 100
236 ms27884 KiB
#include "supertrees.h" #include <vector> int pp[1001][1001]; int n; std::vector<std::vector<int>> answer; bool all1() { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (pp[i][j] != 1) return false; return true; } bool all01() { int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (pp[i][j] > 1) return false; return true; } void solve1() { int i; for (i = 0; i < n - 1; i++) { answer[i][i + 1] = 1; answer[i + 1][i] = 1; } } int color[1001]; int nodes[1001]; int nn; void dfs(int u) { int j; for(j=0; j<n; j++) if (pp[u][j] && !color[j]) { nodes[nn++] = j; color[j] = 1; dfs(j); } } void solve2() { int i, j; for (i = 0; i < n; i++) { if (!color[i]) { nn = 0; color[i] = 1; dfs(i); for (j = 1; j < nn; j++) { answer[nodes[j]][nodes[j - 1]] = 1; answer[nodes[j - 1]][nodes[j]] = 1; } } } } int construct(std::vector<std::vector<int>> p) { n = p.size(); int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) pp[i][j] = p[i][j]; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } if (all1()) solve1(); else if (all01()) solve2(); build(answer); return 1; }
#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...