이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int edge[1000][1000];
int visited[1000];
int par[1000];
pair<int,int> dfs(int v) {
visited[v] = 1;
for (int i = 0; i < n; i++) {
if (edge[v][i] == -1 || visited[i] == 2)
continue;
if (visited[i] == 1)
return { v,i };
par[i] = v;
pair<int,int> tmp = dfs(i);
if (tmp.first != -1)
return tmp;
}
visited[v] = 2;
return { -1,-1 };
}
variant<bool, vector<int>> find_journey(int _n, int m, vector<int> u, vector<int> v) {
n = _n;
memset(edge, -1, sizeof(edge));
for (int i = 0; i < m; i += 2)
edge[u[i]][v[i]] = i;
pair<int,int> x = dfs(0);
if (x.first == -1)
return false;
vector<int> cyc;
cyc.push_back(x.second);
for (int i = x.first;; i = par[i]) {
cyc.push_back(i);
if (i == x.second)
break;
}
vector<int> p;
for (int i = x.second;; i = par[i]) {
p.push_back(i);
if (!i)
break;
}
vector<int> ret;
for (int i = (int)p.size() - 1; i; i--)
ret.push_back(edge[p[i]][p[i - 1]]);
for (int i = (int)cyc.size() - 1; i; i--)
ret.push_back(edge[cyc[i]][cyc[i - 1]]);
for (int i = (int)cyc.size() - 1; i; i--)
ret.push_back(edge[cyc[i]][cyc[i - 1]] + 1);
for (int i = 1; i < (int)cyc.size(); i++)
ret.push_back(edge[cyc[i]][cyc[i - 1]]);
for (int i = 1; i < (int)cyc.size(); i++)
ret.push_back(edge[cyc[i]][cyc[i - 1]] + 1);
for (int i = 1; i < (int)p.size(); i++)
ret.push_back(edge[p[i]][p[i - 1]]);
return ret;
}
# | 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... |