이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
int p[N];
int pi[N];
vector<int> ans;
bool dfs(int x)
{
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 == pi[x] / 2)
continue;
if (!c[h])
{
p[h] = x;
pi[h] = hi;
if (dfs(h))
return true;
}
else
{
return true;
}
}
}
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]) >= 2)
{
return true;
}
return false;
}
p[0] = -3;
pi[0] = -3;
return dfs(0);
/*if (!dfs(0))
return false;
return ans;*/
}
/*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)':
islands.cpp:22: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]
22 | for (int i = 0; i < g[x].size(); ++i)
| ~~^~~~~~~~~~~~~
islands.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
40 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |