Submission #1067219

#TimeUsernameProblemLanguageResultExecution timeMemory
1067219j_vdd16Thousands Islands (IOI22_islands)C++17
0 / 100
2 ms1276 KiB
#include "islands.h" #include <variant> #include <algorithm> #include <bitset> #include <cstdint> #include <cstring> #include <iostream> #include <limits.h> #include <math.h> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> //#define int long long #define loop(X, N) for(int X = 0; X < (N); X++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef uint64_t u64; typedef int64_t i64; int n, m; vvii adj; vb vis; vi succesPath; vi depths; int counter = 0; vii inOut; void dfs(int node, int d, int parent) { vis[node] = true; depths[node] = d; inOut[node].first = counter++; for (auto [child, idx] : adj[node]) { if (child == parent || vis[child]) continue; dfs(child, d + 1, node); } inOut[node].second = counter++; } bool isAncestor(int a, int b) { return inOut[a].first <= inOut[b].first && inOut[b].first <= inOut[a].second; } bool success = false; vi path; vvi marked; int dfs2(int node, int parent) { if (vis[node]) { marked[node] = path; return 1; } vis[node] = true; marked[node] = {}; int count = 0; vi validPaths; for (auto [child, idx] : adj[node]) { if (idx % 2) continue; path.push_back(idx); int res = dfs2(child, node); path.pop_back(); if (res >= 1 && count < 2) { count++; validPaths.push_back(idx); } } if (marked[node].size() && !success) { success = true; succesPath = marked[node]; for (int i = path.size(); i < marked[node].size(); i++) { succesPath.push_back(marked[node][i] ^ 1); } for (int i = marked[node].size(); i >= path.size(); i++) { succesPath.push_back(marked[node][i]); } for (int i = marked[node].size(); i >= path.size(); i++) { succesPath.push_back(marked[node][i] ^ 1); } for (int i = path.size() - 1; i >= 0; i--) { succesPath.push_back(path[i]); } } if (count >= 2 && !success) { //success = true; // succesPath = path; // succesPath.push_back(validPaths[0]); // succesPath.push_back(validPaths[0] ^ 1); // succesPath.push_back(validPaths[1]); // succesPath.push_back(validPaths[1] ^ 1); // succesPath.push_back(validPaths[0] ^ 1); // succesPath.push_back(validPaths[0]); // succesPath.push_back(validPaths[1] ^ 1); // succesPath.push_back(validPaths[1]); // for (int i = path.size() - 1; i >= 0; i--) { // succesPath.push_back(path[i]); // } } return 1; } std::variant<bool, std::vector<int>> find_journey(int N, int M, vi U, vi V) { n = N; m = M; adj = vvii(n); loop(i, m) { adj[U[i]].push_back({V[i], i}); } vis = vb(n); success = false; path = vi(); marked = vvi(n); dfs2(0, -1); if (success) { for (int x : succesPath) { cerr << x << ' '; } cerr << endl; return succesPath; } return false; // return false; // return success; }

Compilation message (stderr)

islands.cpp: In function 'int dfs2(int, int)':
islands.cpp:96:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |         for (int i = path.size(); i < marked[node].size(); i++) {
      |                                   ~~^~~~~~~~~~~~~~~~~~~~~
islands.cpp:99:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for (int i = marked[node].size(); i >= path.size(); i++) {
      |                                           ~~^~~~~~~~~~~~~~
islands.cpp:102:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for (int i = marked[node].size(); i >= path.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...