이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <variant>
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef uint64_t u64;
typedef int64_t i64;
int n, m;
vvi adj1, adj2;
vb vis;
vi depths;
int counter = 0;
vii inOut;
void dfs(int node, int d) {
if (vis[node]) {
return;
}
vis[node] = true;
depths[node] = d;
inOut[node].first = counter++;
for (int child : adj1[node]) {
dfs(node, d + 1);
}
inOut[node].second = counter++;
}
bool isAncestor(int a, int b) {
return inOut[a].first <= inOut[b].first && inOut[b].first <= inOut[a].second;
}
bool success = false;
int isPossible(int node) {
if (vis[node]) {
return node;
}
vis[node] = true;
int furthestBack = node;
int cycleCount = 0;
for (int child : adj1[node]) {
int res = isPossible(child);
if (isAncestor(res, node)) {
cycleCount++;
if (depths[res] < depths[furthestBack]) {
furthestBack = res;
}
}
}
if (cycleCount >= 2) {
success = true;
}
return furthestBack;
}
std::variant<bool, std::vector<int>> find_journey(int N, int M, vi U, vi V) {
n = N;
m = M;
adj1 = vvi(n);
adj2 = vvi(n);
loop(i, m) {
adj1[U[i]].push_back(V[i]);
adj2[V[i]].push_back(U[i]);
}
vis = vb(n);
depths = vi(n);
counter = 0;
inOut = vii(n);
dfs(0, 0);
vis = vb(n);
success = false;
isPossible(0);
return success;
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'void dfs(int, int)':
islands.cpp:54:14: warning: unused variable 'child' [-Wunused-variable]
54 | for (int child : adj1[node]) {
| ^~~~~
# | 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... |