Submission #764410

#TimeUsernameProblemLanguageResultExecution timeMemory
764410raysh07Thousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#include "islands.h"
#include <variant>
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1001;
const int M = 2e5 + 69;
vector <pair<int, int>> adj[N];
bool v1[N], vis[N];
int curr;
int n;
vector <int> path, ok[N], ok1;
pair <int, int> bruh[M];
int dep[N];

void dfs(int u){
    vis[u] = true;
    
    for (auto [v, i] : adj[u]){
        if (v == curr && ok1.size() == 0){
            path.push_back(i);
            ok1 = path;
        } else if (!vis[v]){
            path.push_back(i);
            dfs(v);
            path.pop_back();
        } 
    }
}

void dfs1(int u){
    v1[u] = true;
    ok[u] = path;
    for (auto [v, i] : adj[u]){
        if (!v1[v]){
            dep[v] = dep[u] + 1;
            path.push_back(i);
            dfs1(v);
            path.pop_back();
        }
    }
}

void add(vector <int> &a, vector <int> b, bool rev, int xo = 0){
    if (rev) reverse(b.begin(), b.end());
    for (auto x : b) a.push_back(x ^ xo);
}

vector <int> get(int i){
    vector <int> ans;
    int ong = 0;
    add(ans, ok[i], false);
    
    add(ans, ok1, false);
    add(ans, ok1, false, 1);
    
    add(ans, ok1, true);
    add(ans, ok1, true, 1);
    add(ans, ok[i], true);
    
    for (auto x : ans){
        if (ong != bruh[x].first) assert(false);
        ong = bruh[x].second;
        swap(bruh[x].first, bruh[x].second);
    }
    assert(ong == 0);
    
    return ans;
}

bool comp(int x, int y) return dep[x] < dep[y];

variant<bool, vector<int>> find_journey(int nn, int m, vector<int> u, vector<int> v) {
    n = nn;
    for (int i = 0; i < m; i++){
        bruh[i] = {u[i], v[i]};
    }
    for (int i = 0; i < m; i += 2){
        adj[u[i]].push_back({v[i], i});
    }
    
    dfs1(0);
    vector <int> perm;
    for (int i = 0; i < n; i++) perm.push_back(i);
    sort(perm.begin(), perm.end(), comp);
    
    for (auto i : perm){
        if (v1[i]){
            curr = i;
            path.clear();
            //look for cycle starting and ending at i 
            //good if someone can reach curr 
            
            for (int j = 0; j < n; j++) vis[j] = false;
            dfs(i);
            if (ok1.size()) return get(i);
        }
    }
    return false;
}

Compilation message (stderr)

islands.cpp: In function 'bool comp(int, int)':
islands.cpp:71:25: error: named return values are no longer supported
   71 | bool comp(int x, int y) return dep[x] < dep[y];
      |                         ^~~~~~
islands.cpp:74:9: error: 'nn' was not declared in this scope; did you mean 'n'?
   74 |     n = nn;
      |         ^~
      |         n
islands.cpp:75:25: error: 'm' was not declared in this scope
   75 |     for (int i = 0; i < m; i++){
      |                         ^
islands.cpp:76:20: error: 'u' was not declared in this scope
   76 |         bruh[i] = {u[i], v[i]};
      |                    ^
islands.cpp:76:26: error: 'v' was not declared in this scope
   76 |         bruh[i] = {u[i], v[i]};
      |                          ^
islands.cpp:76:30: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and '<brace-enclosed initializer list>')
   76 |         bruh[i] = {u[i], v[i]};
      |                              ^
In file included from /usr/include/c++/10/utility:70,
                 from /usr/include/c++/10/variant:37,
                 from islands.h:1,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:390:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<int, int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:393:41: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<int, int>&, const std::__nonesuch&>::type' {aka 'const std::pair<int, int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~    
  391 |   __and_<is_copy_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |          is_copy_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |   const pair&, const __nonesuch&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:401:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<int, int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:404:31: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<int, int>&&, std::__nonesuch&&>::type' {aka 'std::pair<int, int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~
  402 |   __and_<is_move_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |          is_move_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |   pair&&, __nonesuch&&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  418 |  operator=(const pair<_U1, _U2>& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note:   template argument deduction/substitution failed:
islands.cpp:76:30: note:   couldn't deduce template parameter '_U1'
   76 |         bruh[i] = {u[i], v[i]};
      |                              ^
In file included from /usr/include/c++/10/utility:70,
                 from /usr/include/c++/10/variant:37,
                 from islands.h:1,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:430:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  430 |  operator=(pair<_U1, _U2>&& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:430:2: note:   template argument deduction/substitution failed:
islands.cpp:76:30: note:   couldn't deduce template parameter '_U1'
   76 |         bruh[i] = {u[i], v[i]};
      |                              ^
islands.cpp:78:25: error: 'm' was not declared in this scope
   78 |     for (int i = 0; i < m; i += 2){
      |                         ^
islands.cpp:79:13: error: 'u' was not declared in this scope
   79 |         adj[u[i]].push_back({v[i], i});
      |             ^
islands.cpp:79:30: error: 'v' was not declared in this scope
   79 |         adj[u[i]].push_back({v[i], i});
      |                              ^
islands.cpp:96:39: error: cannot convert 'std::vector<int>' to 'bool' in return
   96 |             if (ok1.size()) return get(i);
      |                                    ~~~^~~
      |                                       |
      |                                       std::vector<int>