Submission #1242778

#TimeUsernameProblemLanguageResultExecution timeMemory
1242778Zbyszek99Thousands Islands (IOI22_islands)C++20
Compilation error
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

vector<pii> graph_pom[100001];
vector<pii> graph[100001];
vector<pii> graph_trans[100001];
vi comp_graph[100001];
bool was_cycle[100001];
bool odw[100001];
vi post;
int cur_comp = 0;
int comp[100001];
vi comp_list[100001];

void dfs(int v)
{
    odw[v] = 1;
    forall(it,graph[v])
    {
        if(odw[it.ff] == 0) dfs(it.ff);
    }
    post.pb(v);
}

void dfs_comp(int v)
{
    comp_list[cur_comp].pb(v);
    comp[v] = cur_comp;
    odw[v] = 1;
    forall(it,graph_trans[v])
    {
        if(odw[it.ff] == 0) dfs_comp(it.ff);
    }
}

variant<bool,vi> find_journey(int n, int m, vi U, vi V) 
//vi find_journey(int n, int m, vi u, vi v)
{
    unordered_set<int> used;
    rep(i,m)
    {
        graph_pom[u[i]].pb({v[i],i});
    }
    int cur_v = 0;
    vi ans;
    while(siz(graph_pom[cur_v]) <= 1)
    {
        if(siz(graph_pom[cur_v]) == 0) return 0;
        if(odw[cur_v] == 1) return 0;
        odw[cur_v] = 1;
        used.insert(graph_pom[cur_v][0].ss);
        ans.pb(graph_pom[cur_v][0].ss);
        cur_v = graph_pom[cur_v][0].ff;
    }
    rep(i,m)
    {
        if(used.find(i) == used.end())
        {
            graph[u[i]].pb({v[i],i});
            graph_trans[v[i]].pb({u[i],i});
        }
    }
    rep(i,n) odw[i] = 0;
    rep(i,n)
    {
        if(odw[i] == 0)
        {
            dfs(i);
        }
    }
    reverse(all(post));
    rep(i,n) odw[i] = 0;
    forall(it,post)
    {
        if(odw[it] == 0)
        {
            dfs_comp(it);
            cur_comp++;
        }
    }
    rep(i,cur_comp)
    {
        forall(v,comp_list[i])
        {
            forall(it,graph[v])
            {
                if(comp[it.ff] != comp[v])
                {
                    comp_graph[comp[v]].pb(comp[it.ff]);
                }
            }
        }
    }
    for(int c = cur_comp-1; c >= 0; c--)
    {
        if(siz(comp_list[c]) > 1) was_cycle[c] = 1;
        forall(it,comp_graph[c])
        {
            was_cycle[c] = was_cycle[c] || was_cycle[it];
        }
    }
    vi good_edges;
    forall(it,graph[cur_v])
    {
        if(was_cycle[comp[it.ff]])
        {
            good_edges.pb(it.ss);
        }
    }
    if(siz(good_edges) <= 1) return 0;
    return ans;
}

Compilation message (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:63:19: error: 'u' was not declared in this scope
   63 |         graph_pom[u[i]].pb({v[i],i});
      |                   ^
islands.cpp:63:29: error: 'v' was not declared in this scope
   63 |         graph_pom[u[i]].pb({v[i],i});
      |                             ^
islands.cpp:69:47: error: could not convert '0' from 'int' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
   69 |         if(siz(graph_pom[cur_v]) == 0) return 0;
      |                                               ^
      |                                               |
      |                                               int
islands.cpp:70:36: error: could not convert '0' from 'int' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
   70 |         if(odw[cur_v] == 1) return 0;
      |                                    ^
      |                                    |
      |                                    int
islands.cpp:80:19: error: 'u' was not declared in this scope
   80 |             graph[u[i]].pb({v[i],i});
      |                   ^
islands.cpp:80:29: error: 'v' was not declared in this scope
   80 |             graph[u[i]].pb({v[i],i});
      |                             ^
islands.cpp:131:37: error: could not convert '0' from 'int' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
  131 |     if(siz(good_edges) <= 1) return 0;
      |                                     ^
      |                                     |
      |                                     int