제출 #300354

#제출 시각아이디문제언어결과실행 시간메모리
300354Elegia슈퍼트리 잇기 (IOI20_supertrees)C++17
100 / 100
272 ms22264 KiB
#include "supertrees.h" #include <functional> #include <vector> #include <iostream> using namespace std; int construct(vector<vector<int>> p) { int n = p.size(); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (p[i][j] == 3) return 0; vector<vector<int>> answer(n, vector<int>(n)); vector<int> vis(n, -1); int cur = 0, mask = 0; function<void(int)> dfs = [&](int u) { vis[u] = cur; for (int v = 0; v < n; ++v) if (vis[v] == -1 && ((mask >> p[u][v]) & 1)) dfs(v); }; mask = 6; for (int i = 0; i < n; ++i) if (vis[i] == -1) { cur = i; dfs(i); } for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (vis[i] == vis[j] && !p[i][j]) return 0; mask = 2; auto vis2 = vis; vis.assign(n, -1); for (int i = 0; i < n; ++i) if (vis[i] == -1) { cur = i; dfs(i); } for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (vis[i] == vis[j] && p[i][j] == 2) return 0; vector<int> cand(n, -1); vector<vector<int>> cycs(n); for (int i = 0; i < n; ++i) { if (cand[vis[i]] == -1) { cand[vis[i]] = i; cycs[vis2[i]].push_back(i); } else { answer[cand[vis[i]]][i] = answer[i][cand[vis[i]]] = 1; } } for (auto cyc : cycs) { if (cyc.size() > 1) { if (cyc.size() < 3) return 0; answer[cyc[0]][cyc.back()] = answer[cyc.back()][cyc[0]] = 1; for (int i = 1; i < cyc.size(); ++i) answer[cyc[i - 1]][cyc[i]] = answer[cyc[i]][cyc[i - 1]] = 1; } } build(answer); return 1; }

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

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