#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> ord;
int vis[200005];
vector<int> adj[200005];
void dfs(int i, int d, vector<int> proc) {
if (vis[i]) {
return;
}
vis[i] = 1;
proc.push_back(i);
if (d > ans) {
d = ans;
ord = proc;
}
for (int j : adj[i]) {
dfs(j, d+1, proc);
}
proc.pop_back();
vis[i] = 0;
}
vector<int> longest_trip(int n, int d) {
for (int i = 0; i < n; i++) {
adj[i].clear();
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (are_connected({i}, {j})) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
ans = 0;
ord.clear();
for (int i = 0; i < n; i++) {
dfs(i, 0, {});
}
return ord;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
3023 ms |
5712 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
3085 ms |
4952 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
3077 ms |
4952 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
3091 ms |
4952 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
3085 ms |
4952 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |