# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836379 | SamAnd | Thousands Islands (IOI22_islands) | C++17 | 26 ms | 5288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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;
}
vector<int> yans = ans;
ans.push_back(v[0].se);
ans.push_back((v[0].se ^ 1));
ans.push_back(v[1].se);
ans.push_back((v[1].se ^ 1));
ans.push_back((v[0].se ^ 1));
ans.push_back(v[0].se);
ans.push_back((v[1].se ^ 1));
ans.push_back(v[1].se);
for (int i = sz(yans) - 1; i >= 0; --i)
ans.push_back(yans[i]);
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
*/
Compilation message (stderr)
# | 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... |