제출 #628564

#제출 시각아이디문제언어결과실행 시간메모리
628564Sorting수천개의 섬 (IOI22_islands)C++17
13.40 / 100
38 ms4812 KiB
#include "islands.h" #include <variant> #include <vector> #include <algorithm> #include <cmath> using namespace std; std::variant<bool, std::vector<int>> find_journey( int n, int m, std::vector<int> u, std::vector<int> v) { if(n == 2){ vector<int> cnt[2]{}; for(int i = 0; i < u.size();++i){ cnt[u[i]].push_back(i); } if(cnt[0].size() >= 2 && cnt[1].size() >= 1){ return vector<int>{cnt[0][0], cnt[1][0], cnt[0][1], cnt[0][0], cnt[1][0], cnt[0][1]}; } return false; } vector<vector<pair<int, int>>> adj(n); for(int i = 0; i < m; i += 2) adj[u[i]].push_back({v[i], i}); vector<int> vis(n); function<bool(int, int)> dfs = [&](int u, int par = -1) -> bool{ vis[u] = 1; for(auto p: adj[u]){ int to = p.first; if(vis[to] == 1) return true; if(vis[to] == 2) continue; if(dfs(to, u)) return true; } vis[u] = 2; return false; }; return dfs(0, -1); /* int x = 0, par = -1; while(true){ if(adj[x].size() != 1 + (x != 0)){ if(adj[x].size() < 1 + (x != 0)){ return false; } int len = ans.size(); pair<int, int> to_1{-1, -1}, to_2{-1, -1}; for(auto p: adj[x]){ if(p.first == par){ continue; } if(to_1.first == -1) to_1 = p; else to_2 = p; } if(to_1.first == to_2.first){ pair<int, int> back_1{-1, -1}, back_2{-1, -1}; for(auto p: adj[to_1.first]){ if(p.first != x){ continue; } if(back_1.first == -1) back_1 = p; else back_2 = p; } ans.push_back(to_1.second); ans.push_back(back_1.second); ans.push_back(to_2.second); ans.push_back(to_1.second); ans.push_back(back_1.second); ans.push_back(to_2.second); } else{ pair<int, int> back_1{-1, -1}, back_2{-1, -1}; for(auto p: adj[to_1.first]){ if(p.first != x) continue; back_1 = p; break; } for(auto p: adj[to_2.first]){ if(p.first != x) continue; back_2 = p; break; } ans.push_back(to_1.second); ans.push_back(back_1.second); ans.push_back(to_2.second); ans.push_back(back_2.second); ans.push_back(back_1.second); ans.push_back(to_1.second); ans.push_back(back_2.second); ans.push_back(to_2.second); } for(int i = len - 1; i >= 0; --i) ans.push_back(ans[i]); return ans; } for(auto p: adj[x]){ int to = p.first; int idx = p.second; if(to == par){ par = -1; continue; } par = x; x = to; ans.push_back(idx); break; } }*/ }

컴파일 시 표준 에러 (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:14:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for(int i = 0; i < u.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...