이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
int find_connected(int v, vector<int> arr) {
if (arr.size() == 0 || !are_connected({v}, arr)) return -1;
int s = 0, e = arr.size() - 1;
while (s < e) {
int m = (s + e) / 2;
vector<int> temp;
for (int i = s; i <= m; i++) temp.push_back(arr[i]);
if (are_connected({v}, temp)) e = m;
else s = m + 1;
}
return arr[s];
}
vector<int> longest_trip(int N, int D) {
int n = N;
vector<int> res;
int ch[256]; for (int i = 0; i < n; i++) ch[i] = 0;
vector<int> path, clique;
path.push_back(0);
ch[0] = 1;
while (true) {
vector<int> temp;
for (int i = 0; i < n; i++) if (ch[i] == 0) temp.push_back(i);
int v = find_connected(path.back(), temp);
if (v == -1) break;
path.push_back(v);
ch[v] = 1;
}
for (int i = 0; i < n; i++) if (ch[i] == 0) clique.push_back(i);
bool connected = false;
if (path.size() > 0 && clique.size() > 0) connected = are_connected(path, clique);
if (connected) {
int target = find_connected(path[0], clique);
if (target != -1) {
res = path;
reverse(res.begin(), res.end());
int t = 0;
for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
swap(clique[0], clique[t]);
for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
return res;
}
int s = path.size() - 1;
target = find_connected(path[s], clique);
if (target != -1) {
res = path;
int t = 0;
for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
swap(clique[0], clique[t]);
for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
return res;
}
for (int i = 0; i < clique.size(); i++) {
target = find_connected(clique[i], path);
if (target == -1) continue;
swap(clique[i], clique.back());
res = clique;
while (path[0] != target) {
int front = path[0];
path.erase(path.begin());
path.push_back(front);
}
for (int k = 0; k < path.size(); k++) res.push_back(path[k]);
return res;
}
}
else {
if (path.size() > clique.size()) return path;
return clique;
}
return {}; // never reached
}
컴파일 시 표준 에러 (stderr) 메시지
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < clique.size(); i++) {
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int k = 0; k < path.size(); k++) res.push_back(path[k]);
| ~~^~~~~~~~~~~~~| # | 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... |