제출 #628738

#제출 시각아이디문제언어결과실행 시간메모리
628738dqhungdl수천개의 섬 (IOI22_islands)C++17
10 / 100
64 ms28840 KiB
#include "islands.h" #include <bits/stdc++.h> #include <variant> using namespace std; const int MAX = 1e5 + 5; int N; bool mark[MAX]; vector<vector<vector<int>>> g; vector<int> path, special; bool dfs(int u, int p) { if (mark[u]) return false; mark[u] = true; for (int v = 0; v < N; v++) { if (v != p && !g[u][v].empty()) { if (!v) { path.push_back(0); return true; } if (dfs(v, u)) { path.push_back(v); return true; } } } return false; } bool dfsSpecial(int u, int p) { if (mark[u]) return false; mark[u] = true; if (special[u] != -1) { path.push_back(special[u]); path.push_back(u); return true; } for (int v = 0; v < N; v++) if (v != p && !g[u][v].empty()) if (dfsSpecial(v, u)) { path.push_back(u); return true; } return false; } variant<bool, vector<int>> find_journey(int _N, int M, vector<int> U, vector<int> V) { N = _N; if (N == 2) { vector<int> g[2]; for (int i = 0; i < M; i++) g[U[i]].push_back(i); if (g[0].size() < 2 || g[1].empty()) return false; return vector<int>({g[0][0], g[1][0], g[0][1], g[0][0], g[1][0], g[0][1]}); } g.resize(N, vector<vector<int>>(N)); for (int i = 0; i < M; i++) g[U[i]][V[i]].push_back(i); bool isClique = true; for (int i = 0; i < N && isClique; i++) for (int j = 0; j < N && isClique; j++) if (i != j && g[i][j].empty()) isClique = false; if (isClique) return vector<int>({g[0][1][0], g[1][2][0], g[2][0][0], g[0][2][0], g[2][1][0], g[1][0][0], g[2][0][0], g[1][2][0], g[0][1][0], g[1][0][0], g[2][1][0], g[0][2][0]}); special.resize(N, -1); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j && g[i][j].size() >= 2 && g[j][i].size() >= 1) special[i] = j; if (dfsSpecial(0, 0)) { reverse(path.begin(), path.end()); vector<int> rs; for (int i = 0; i < path.size() - 2; i++) rs.push_back(g[path[i]][path[i + 1]][0]); int u = path[path.size() - 2], v = path.back(); rs.push_back(g[u][v][0]); rs.push_back(g[v][u][0]); rs.push_back(g[u][v][1]); rs.push_back(g[u][v][0]); rs.push_back(g[v][u][0]); rs.push_back(g[u][v][1]); for (int i = (int) path.size() - 3; i >= 0; i--) rs.push_back(g[path[i]][path[i + 1]][0]); return rs; } path.clear(); for (int i = 0; i < N; i++) mark[i] = false; bool isDoubled = M % 2 == 0; for (int i = 1; i < M && isDoubled; i += 2) if (U[i - 1] != U[i] || V[i - 1] != V[i]) isDoubled = false; if (isDoubled) { if (dfs(0, 0)) { path.push_back(0); reverse(path.begin(), path.end()); vector<int> rs; for (int t = 1; t < path.size(); t++) { for (int i = 0; i < path.size() - 1; i++) rs.push_back(g[path[i]][path[i + 1]][0]); for (int i = 0; i < path.size() - 1; i++) rs.push_back(g[path[i]][path[i + 1]][1]); } return rs; } return false; } return false; } //int main() { // freopen("../_input", "r", stdin); // int N, M; // assert(2 == scanf("%d %d", &N, &M)); // // vector<int> U(M), V(M); // for (int i = 0; i < M; ++i) { // assert(2 == scanf("%d %d", &U[i], &V[i])); // } // // variant<bool, vector<int>> result = find_journey(N, M, U, V); // if (result.index() == 0) { // printf("0\n"); // if (get<bool>(result)) { // printf("1\n"); // } else { // printf("0\n"); // } // } else { // printf("1\n"); // vector<int> &canoes = get<vector<int>>(result); // printf("%d\n", static_cast<int>(canoes.size())); // for (int i = 0; i < static_cast<int>(canoes.size()); ++i) { // if (i > 0) { // printf(" "); // } // printf("%d", canoes[i]); // } // printf("\n"); // } // return 0; //}

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

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:80:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for (int i = 0; i < path.size() - 2; i++)
      |                         ~~^~~~~~~~~~~~~~~~~
islands.cpp:106:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |             for (int t = 1; t < path.size(); t++) {
      |                             ~~^~~~~~~~~~~~~
islands.cpp:107:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |                 for (int i = 0; i < path.size() - 1; i++)
      |                                 ~~^~~~~~~~~~~~~~~~~
islands.cpp:109:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 for (int i = 0; i < path.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...