제출 #836373

#제출 시각아이디문제언어결과실행 시간메모리
836373SamAndThousands Islands (IOI22_islands)C++17
컴파일 에러
0 ms0 KiB
#include "islands.h"
#include <variant>
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 1003, M = 200005;

vector<pair<int, int> > g[N];

bool c[N];
vector<int> ans;
bool dfs(int x, vector<int>& v)
{
    c[x] = true;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i].fi;
        int hi = g[x][i].se;
        if (hi / 2 == v.back() / 2)
            continue;
        if (!c[h])
        {
            p[h] = x;
            pi[h] = hi;
            if (dfs(h))
                return true;
        }
        else
        {
            return true;
        }
    }
    return false;
}

std::variant<bool, std::vector<int> > find_journey(int N, int M, std::vector<int> U, std::vector<int> V)
{
    for (int i = 0; i < M; ++i)
    {
        g[U[i]].push_back(m_p(V[i], i));
    }
    if (N == 2)
    {
        if (sz(g[0]) >= 2 && sz(g[1]) >= 1)
        {
            ans.push_back(g[0][0].se);
            ans.push_back(g[1][0].se);
            ans.push_back(g[0][1].se);
            ans.push_back(g[0][0].se);
            ans.push_back(g[1][0].se);
            ans.push_back(g[0][1].se);
            return ans;
        }
        return false;
    }

    int x = 0;
    while (1)
    {
        vector<pair<int, int> > v;
        for (int i = 0; i < g[x].size(); ++i)
        {
            int h = g[x][i].fi;
            int hi = g[x][i].se;
            if (!ans.empty() && ans.back() / 2 == hi / 2)
                continue;
            v.push_back(m_p(h, hi));
        }
        if (v.empty())
            return false;
        if (sz(v) == 1)
        {
            ans.push_back(v[0].se);
            x = v[0].fi;
            continue;
        }
        return true;
    }
}

/*int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> u, v;
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        u.push_back(x);
        v.push_back(y);
    }
    cout << find_journey(n, m, u, v) << "\n";
    return 0;
}*/

/*
5 6
0 1
1 0
1 3
3 1
0 4
4 0

3 6
0 1
1 0
1 2
2 1
2 0
0 2
*/

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In function 'bool dfs(int, std::vector<int>&)':
islands.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
islands.cpp:28:13: error: 'p' was not declared in this scope
   28 |             p[h] = x;
      |             ^
islands.cpp:29:13: error: 'pi' was not declared in this scope; did you mean 'hi'?
   29 |             pi[h] = hi;
      |             ^~
      |             hi
islands.cpp:30:22: error: too few arguments to function 'bool dfs(int, std::vector<int>&)'
   30 |             if (dfs(h))
      |                      ^
islands.cpp:17:6: note: declared here
   17 | bool dfs(int x, vector<int>& v)
      |      ^~~
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:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i < g[x].size(); ++i)
      |                         ~~^~~~~~~~~~~~~