이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <variant>
#include <vector>
#include <stdlib.h>
using namespace std;
typedef vector<int> vi;
typedef variant<bool, vi> vbvi;
const int N = 100000, M = 200000;
int ij[M];
int *eh[N], eo[N], eo_[N], *fh[N], fo[N]; char deleted[N];
void append(int **eh, int *eo, int i, int h) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
eh[i] = (int *) realloc(eh[i], o * 2 * sizeof *eh[i]);
eh[i][o] = h;
}
void dfs(int j) {
if (deleted[j] || eo_[j])
return;
deleted[j] = 1;
for (int o = fo[j]; o--; ) {
int h = fh[j][o], i = j ^ ij[h];
eo_[i]--, dfs(i);
}
}
vbvi find_journey(int n, int m, vi ii, vi jj) {
for (int i = 0; i < n; i++) {
eh[i] = (int *) malloc(2 * sizeof *eh[i]);
fh[i] = (int *) malloc(2 * sizeof *fh[i]);
}
for (int h = 0; h < m; h++) {
int i = ii[h], j = jj[h];
ij[h] = i ^ j;
append(eh, eo, i, h), append(fh, fo, j, h), eo_[i]++;
}
for (int i = 0; i < n; i++)
dfs(i);
int s = 0;
while (1) {
if (eo_[s] == 0)
return false;
if (eo_[s] >= 2)
return true;
for (int o = eo[s]; o--; ) {
int h = eh[s][o], i = s ^ ij[h];
if (!deleted[i]) {
eo_[s] = 0, dfs(s);
s = i;
break;
}
}
}
return true;
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'void append(int**, int*, int, int)':
islands.cpp:18:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
18 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
# | 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... |