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;
vector<int> longest_trip(int n, int D)
{
vector<int> used(n, 0);
vector<int> v1, v2, cur;
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (are_connected({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;
if (!v1.empty() && !v2.empty() && are_connected(v1, {i}) && are_connected(v2, {i}))
{
cur.clear();
for (int x : v1) cur.push_back(x);
cur.push_back(i);
for (int x : v2) cur.push_back(x);
v1 = cur;
v2.clear();
}
else if (are_connected(v1, {i}))
{
vector<int> nw;
int idx = -1;
for (int j = 0; j < v1.size(); j++)
{
if (are_connected({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 (v2.empty()) v2.push_back(i);
else
{
vector<int> nw;
int idx = -1;
for (int j = 0; j < v2.size(); j++)
{
if (are_connected({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;
}
}
// cout << i << ":\n";
// for (int x : v1) cout << x << ' ';
// cout << '\n';
// for (int x : v2) cout << x << ' ';
// cout << '\n';
// for (int x : cur) cout << x << ' ';
// cout << '\n';
}
if (max({v1.size(), v2.size(), cur.size()}) == v1.size()) return v1;
if (max({v1.size(), v2.size(), cur.size()}) == v2.size()) return v2;
return cur;
}
Compilation message (stderr)
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int j = 0; j < v1.size(); j++)
| ~~^~~~~~~~~~~
longesttrip.cpp:61:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | 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... |