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 <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
int A[300][300];
int ask(vector<int> a, vector<int> b)
{
for (int x : a)
{
for (int y : b)
{
if (A[x][y]) return 1;
}
}
return 0;
}
vector<int> longest_trip(int n, int D)
{
int c = 0;
for (int i = 0; i < n; i++)
{
A[i][i] = 1;
for (int j = i + 1; j < n; j++)
{
A[i][j] = A[j][i] = are_connected({i}, {j});
}
}
vector<int> used(n, 0);
vector<int> v1, v2;
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (ask({i}, {j}))
{
v1.push_back(i), v1.push_back(j);
used[i] = used[j] = 1;
break;
}
}
if (!v1.empty()) break;
}
for (int i = 0; i < n; i++)
{
if (used[i]) continue;
used[i] = 1;
if (ask(v1, {i}) && ask(v2, {i}))
{
assert(++c <= 1);
int id1 = -1, id2 = -1;
for (int j = 0; j < v1.size(); j++)
{
if (ask({v1[j]}, {i}))
{
id1 = j;
break;
}
}
for (int j = 0; j < v2.size(); j++)
{
if (ask({v2[j]}, {i}))
{
id2 = j;
break;
}
}
assert(id1 != -1 && id2 != -1);
vector<int> nw;
for (int j = (id2 + 1) % v2.size(); 1; j = (j + 1) % v2.size())
{
nw.push_back(v2[j]);
if (j == id2) break;
}
nw.push_back(i), nw.push_back(v1[id1]);
for (int j = (id1 + 1) % v1.size(); j != id1; j = (j + 1) % v1.size())
{
nw.push_back(v1[j]);
}
v2.clear();
v1 = nw;
}
else if (ask(v1, {i}))
{
vector<int> nw;
int idx = -1;
if (ask({v1[0]}, {i}))
{
nw.push_back(i);
for (int x : v1) nw.push_back(x);
}
else if (ask({v1.back()}, {i}))
{
nw = v1;
nw.push_back(i);
}
else
{
for (int j = 0; j < v1.size(); j++)
{
if (ask({i}, {v1[j]}))
{
idx = j;
break;
}
}
nw.push_back(i), nw.push_back(v1[idx]);
for (int j = (idx + 1) % v1.size(); j != idx; j = (j + 1) % v1.size())
{
nw.push_back(v1[j]);
}
}
v1 = nw;
}
else if (ask(v2, {i}))
{
vector<int> nw;
int idx = -1;
if (ask({v2[0]}, {i}))
{
nw.push_back(i);
for (int x : v2) nw.push_back(x);
}
else if (ask({v2.back()}, {i}))
{
nw = v2;
nw.push_back(i);
}
else
{
for (int j = 0; j < v2.size(); j++)
{
if (ask({i}, {v2[j]}))
{
idx = j;
break;
}
}
nw.push_back(i), nw.push_back(v2[idx]);
for (int j = (idx + 1) % v2.size(); j != idx; j = (j + 1) % v2.size())
{
nw.push_back(v2[j]);
}
}
v2 = nw;
}
else v2.push_back(i);
}
if (v1.size() > v2.size()) return v1;
else return v2;
};
Compilation message (stderr)
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:54:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int j = 0; j < v1.size(); j++)
| ~~^~~~~~~~~~~
longesttrip.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int j = 0; j < v2.size(); j++)
| ~~^~~~~~~~~~~
longesttrip.cpp:101:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int j = 0; j < v1.size(); j++)
| ~~^~~~~~~~~~~
longesttrip.cpp:133:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | for (int j = 0; j < v2.size(); j++)
| ~~^~~~~~~~~~~
# | 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... |