#include "longesttrip.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
vvi paths;
vi visited;
vi cur_path;
int node,dis;
void dfs(int pos,int height,vi cur){
if(visited[pos])return;
cur.pb(pos);
visited[pos] = 1;
if(dis < height){
dis = height;
node = pos;
cur_path = cur;
}
for(int a:paths[pos]){
dfs(a,height+1,cur);
}
}
vi longest_trip(int N, int D)
{
paths = vvi(N);
FOR(i,0,N){
FOR(j,i+1,N){
if(are_connected({i},{j})){
paths[i].pb(j);
paths[j].pb(i);
}
}
}
visited = vi(N,0);
vi possibles;
FOR(i,0,N){
if(visited[i])continue;
node = -1;
dis = -1;
vi cur;
dfs(i,1,cur);
if(node != -1)possibles.pb(node);
}
visited = vi(N,0);
int temp = -1;
vi ans;
for(int i:possibles){
node = -1;
dis = -1;
vi cur;
dfs(i,1,cur);
if(temp < dis){
temp = dis;
ans = cur_path;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
187 ms |
1128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Correct |
162 ms |
592 KB |
Output is correct |
4 |
Correct |
434 ms |
832 KB |
Output is correct |
5 |
Correct |
804 ms |
1576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
147 ms |
444 KB |
Output is correct |
4 |
Correct |
404 ms |
744 KB |
Output is correct |
5 |
Correct |
791 ms |
1308 KB |
Output is correct |
6 |
Correct |
8 ms |
340 KB |
Output is correct |
7 |
Correct |
28 ms |
344 KB |
Output is correct |
8 |
Correct |
161 ms |
344 KB |
Output is correct |
9 |
Correct |
298 ms |
804 KB |
Output is correct |
10 |
Correct |
870 ms |
1320 KB |
Output is correct |
11 |
Correct |
835 ms |
1040 KB |
Output is correct |
12 |
Correct |
862 ms |
1292 KB |
Output is correct |
13 |
Correct |
778 ms |
1296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
344 KB |
Output is correct |
3 |
Correct |
145 ms |
464 KB |
Output is correct |
4 |
Correct |
399 ms |
860 KB |
Output is correct |
5 |
Correct |
763 ms |
1296 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
140 ms |
592 KB |
Output is correct |
9 |
Correct |
252 ms |
868 KB |
Output is correct |
10 |
Correct |
738 ms |
1068 KB |
Output is correct |
11 |
Correct |
753 ms |
1140 KB |
Output is correct |
12 |
Correct |
718 ms |
1076 KB |
Output is correct |
13 |
Correct |
677 ms |
1288 KB |
Output is correct |
14 |
Correct |
5 ms |
344 KB |
Output is correct |
15 |
Correct |
10 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
17 |
Correct |
76 ms |
344 KB |
Output is correct |
18 |
Correct |
135 ms |
592 KB |
Output is correct |
19 |
Correct |
245 ms |
980 KB |
Output is correct |
20 |
Correct |
259 ms |
788 KB |
Output is correct |
21 |
Correct |
741 ms |
1252 KB |
Output is correct |
22 |
Correct |
667 ms |
1244 KB |
Output is correct |
23 |
Correct |
737 ms |
1212 KB |
Output is correct |
24 |
Correct |
708 ms |
1224 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
25 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
344 KB |
Output is correct |
29 |
Correct |
18 ms |
344 KB |
Output is correct |
30 |
Correct |
170 ms |
468 KB |
Output is correct |
31 |
Correct |
164 ms |
596 KB |
Output is correct |
32 |
Correct |
178 ms |
608 KB |
Output is correct |
33 |
Correct |
276 ms |
1112 KB |
Output is correct |
34 |
Correct |
288 ms |
344 KB |
Output is correct |
35 |
Correct |
317 ms |
848 KB |
Output is correct |
36 |
Correct |
766 ms |
1212 KB |
Output is correct |
37 |
Correct |
785 ms |
1132 KB |
Output is correct |
38 |
Correct |
720 ms |
908 KB |
Output is correct |
39 |
Correct |
710 ms |
1080 KB |
Output is correct |
40 |
Correct |
781 ms |
968 KB |
Output is correct |
41 |
Correct |
848 ms |
1168 KB |
Output is correct |
42 |
Correct |
769 ms |
864 KB |
Output is correct |
43 |
Correct |
783 ms |
1104 KB |
Output is correct |
44 |
Correct |
707 ms |
1796 KB |
Output is correct |
45 |
Correct |
6 ms |
344 KB |
Output is correct |
46 |
Correct |
9 ms |
344 KB |
Output is correct |
47 |
Correct |
22 ms |
344 KB |
Output is correct |
48 |
Correct |
16 ms |
344 KB |
Output is correct |
49 |
Correct |
23 ms |
344 KB |
Output is correct |
50 |
Correct |
172 ms |
692 KB |
Output is correct |
51 |
Correct |
192 ms |
600 KB |
Output is correct |
52 |
Correct |
217 ms |
600 KB |
Output is correct |
53 |
Correct |
310 ms |
624 KB |
Output is correct |
54 |
Correct |
295 ms |
720 KB |
Output is correct |
55 |
Correct |
338 ms |
592 KB |
Output is correct |
56 |
Correct |
834 ms |
1108 KB |
Output is correct |
57 |
Correct |
830 ms |
1028 KB |
Output is correct |
58 |
Correct |
797 ms |
984 KB |
Output is correct |
59 |
Correct |
840 ms |
1112 KB |
Output is correct |
60 |
Correct |
805 ms |
1104 KB |
Output is correct |
61 |
Correct |
751 ms |
1200 KB |
Output is correct |
62 |
Correct |
775 ms |
976 KB |
Output is correct |
63 |
Correct |
706 ms |
1320 KB |
Output is correct |
64 |
Correct |
736 ms |
1096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
344 KB |
Output is correct |
3 |
Partially correct |
117 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
349 ms |
484 KB |
Output is partially correct |
5 |
Partially correct |
726 ms |
1108 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Partially correct |
142 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
303 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
812 ms |
1228 KB |
Output is partially correct |
11 |
Partially correct |
820 ms |
1332 KB |
Output is partially correct |
12 |
Partially correct |
785 ms |
1076 KB |
Output is partially correct |
13 |
Partially correct |
761 ms |
1068 KB |
Output is partially correct |
14 |
Correct |
13 ms |
344 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |