Submission #1211636

#TimeUsernameProblemLanguageResultExecution timeMemory
1211636serkanrashidThousands Islands (IOI22_islands)C++20
Compilation error
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

struct edge
{
    int ver,num;
    edge(){};
    edge(int vi, int ni)
    {
        ver = vi;
        num = ni;
    }
};

const int MAXN = 2e5+5;
int n,m,u[MAXN],v[MAXN];

int idx,ans[MAXN];
vector<edge>g[MAXN],vector<edge>o[MAXN];///obraten

vector<int>v0[MAXN],v1[MAXN];

void solve1()
{
    for(edge nb : g[0])
    {
        v0[nb.ver].push_back(nb.num);
    }
    for(edge nb : o[0])
    {
        v1[nb.ver].push_back(nb.num);
    }

    for(int i = 1; i < n; i++)
    {
        if((int)v0[i].size() >= 2 && (int)v1[i].size() >= 1)
        {
            int u1 = v0[i][0];
            int u2 = v0[i][1];
            int v = v1[i][0];
            ans[idx] = u1;
            ans[idx+1] = v;
            ans[idx+2] = u2;
            ans[idx+3] = u1;
            ans[idx+4] = v;
            ans[idx+5] = u2;
            idx += 6;
            break;
        }
    }
}

struct PAR
{
    int p,num;
};

int used[MAXN];
PAR par[MAXN];
int cikul,num_e;

void dfs(int beg)
{
    used[beg] = 1;
    for(edge nb : g[beg])
    {
        if(cikul != -1) return;

        if(used[nb.ver] && nb.ver != 0)
        {
            cikul = beg;
            num_e = nb.num;
            return;
        }
        else
        {
            par[nb.ver] = {beg,nb.num};
            dfs(nb.ver);
        }
    }
}

vector<int> is_cycle()
{
    for(int i = 0; i < n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) par[i] = {-1,-1};

    cikul = -1;
    par[0] = 0;
    dfs(0);


    vector<int>sp;
    if(cikul == -1) return sp;


    sp.push_back(num_e);
    int kraj = v[num_e];

    int x = cikul;
    while(x != kraj)
    {
        sp.push_back(par[x].num);
        x = par[x].p;
    }
    reverse(sp.begin(),sp.end());

    vector<int>put;
    ///x = kraj;
    while(x != 0)
    {
        sp.push_back(par[x].num);
        x = par[x].p;
    }
    reverse(put.begin(),put.end());

    vector<int>ans;
    for(int h : put) ans.push_back(h);
    for(int h : sp) ans.push_back(h);
    for(int i = (int)put.size() - 1; i >= 0; i--) ans.push_back(put[i]);

    for(int h : put) ans.push_back(h);
    for(int i = (int)sp.size() - 1; i >= 0; i--) ans.push_back(sp[i]);
    for(int i = (int)put.size() - 1; i >= 0; i--) ans.push_back(put[i]);
    return ans;
}

variant <bool, vector<int> > find_journey(int N, int M, vector<int> U, vector<int> V)
{
    n = N;
    m = M;
    for(int i = 0; i < M; i++)
    {
        u[i] = U[i];
        v[i] = V[i];
        g[u[i]].push_back({v[i],i});
        o[v[i]].push_back({u[i],i});
    }
    solve1();
    if(idx != 0)
    {
        vector<int>res;
        res.resize(idx);
        for(int i = 0; i < idx; i++) res[i] = ans[i];
        return res;
    }

    vector<int> res = is_cycle();
    if((int)res.size()) return res;

    return false;
}

Compilation message (stderr)

islands.cpp:22:33: error: invalid declarator before 'o'
   22 | vector<edge>g[MAXN],vector<edge>o[MAXN];///obraten
      |                                 ^
islands.cpp: In function 'void solve1()':
islands.cpp:32:19: error: 'o' was not declared in this scope
   32 |     for(edge nb : o[0])
      |                   ^
islands.cpp: In function 'std::vector<int> is_cycle()':
islands.cpp:92:14: error: no match for 'operator=' (operand types are 'PAR' and 'int')
   92 |     par[0] = 0;
      |              ^
islands.cpp:56:8: note: candidate: 'constexpr PAR& PAR::operator=(const PAR&)'
   56 | struct PAR
      |        ^~~
islands.cpp:56:8: note:   no known conversion for argument 1 from 'int' to 'const PAR&'
islands.cpp:56:8: note: candidate: 'constexpr PAR& PAR::operator=(PAR&&)'
islands.cpp:56:8: note:   no known conversion for argument 1 from 'int' to 'PAR&&'
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:140:9: error: 'o' was not declared in this scope
  140 |         o[v[i]].push_back({u[i],i});
      |         ^