# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073369 | 2024-08-24T13:37:42 Z | Unforgettablepl | Longest Trip (IOI23_longesttrip) | C++17 | 936 ms | 1556 KB |
#pragma GCC optimize("Ofast","unroll-all-loops") #include "longesttrip.h" #include <bits/stdc++.h> using namespace std; vector<int> longest_trip(int N,int D){ vector<vector<int>> adj(N); vector areConnected(N,vector<bool>(N)); for(int i=0;i<N;i++) { for(int j=i+1;j<N;j++) { if(are_connected({i},{j})) { adj[i].emplace_back(j); adj[j].emplace_back(i); areConnected[i][j]=areConnected[j][i]=true; } } } { // Case 1 if two components int isTwo = -1; { vector<bool> visited(N); int curr = 0; function<void(int)> dfs = [&](int x) { if(visited[x])return; visited[x]=true; curr++; for(int&i:adj[x])dfs(i); }; dfs(0); if(curr!=N) { if(curr>=N-curr)isTwo=0; else { for(int i=0;i<N;i++) { if(!visited[i]){ isTwo=i;break; } } } } } if(isTwo!=-1) { vector<bool> visited(N); vector<int> ans; function<void(int)> dfs = [&](int x) { visited[x]=true; ans.emplace_back(x); for(int&i:adj[x])if(!visited[i]) { dfs(i); return; } }; dfs(isTwo); return ans; } } vector<vector<int>> path(3); vector<bool> visited(N); function<int(int,int)> dfs = [&](int x,int def) { visited[x]=true; int state = def; int children = 0; for(int&i:adj[x])if(!visited[i]) { children++; if(children==2) { assert(dfs(i,2)==2); state=0; break; } auto ans = dfs(i,def); if(ans==0) { state = 0; break; } } path[state].emplace_back(x); return state; }; auto curr = dfs(0,1); if(curr==1) { return path[1]; } assert(curr==0); if(path[0].size()==1) { vector<int> ans = path[1]; ans.emplace_back(path[0][0]); reverse(path[2].begin(),path[2].end()); for(int&i:path[2])ans.emplace_back(i); return ans; } if(!areConnected[path[0][1]][path[1][0]])swap(path[1],path[2]); assert(areConnected[path[0][1]][path[1][0]]); path[1].emplace_back(path[0][0]); path[0].erase(path[0].begin()); reverse(path[0].begin(),path[0].end()); reverse(path[2].begin(),path[2].end()); auto ans = path[0]; for(int&i:path[1])ans.emplace_back(i); for(int&i:path[2])ans.emplace_back(i); assert(ans.size()==N); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 184 ms | 924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 17 ms | 344 KB | Output is correct |
3 | Correct | 150 ms | 436 KB | Output is correct |
4 | Correct | 424 ms | 964 KB | Output is correct |
5 | Correct | 894 ms | 1224 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 | 147 ms | 444 KB | Output is correct |
4 | Correct | 433 ms | 732 KB | Output is correct |
5 | Correct | 844 ms | 1020 KB | Output is correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 27 ms | 600 KB | Output is correct |
8 | Correct | 159 ms | 456 KB | Output is correct |
9 | Correct | 346 ms | 716 KB | Output is correct |
10 | Correct | 874 ms | 1072 KB | Output is correct |
11 | Correct | 868 ms | 1012 KB | Output is correct |
12 | Correct | 747 ms | 1192 KB | Output is correct |
13 | Correct | 852 ms | 864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 23 ms | 344 KB | Output is correct |
3 | Correct | 148 ms | 460 KB | Output is correct |
4 | Correct | 411 ms | 1008 KB | Output is correct |
5 | Correct | 831 ms | 1196 KB | Output is correct |
6 | Correct | 10 ms | 344 KB | Output is correct |
7 | Correct | 27 ms | 600 KB | Output is correct |
8 | Correct | 148 ms | 452 KB | Output is correct |
9 | Correct | 354 ms | 1104 KB | Output is correct |
10 | Correct | 770 ms | 1256 KB | Output is correct |
11 | Correct | 862 ms | 828 KB | Output is correct |
12 | Correct | 832 ms | 948 KB | Output is correct |
13 | Correct | 797 ms | 1120 KB | Output is correct |
14 | Correct | 5 ms | 344 KB | Output is correct |
15 | Correct | 12 ms | 344 KB | Output is correct |
16 | Correct | 44 ms | 344 KB | Output is correct |
17 | Correct | 78 ms | 592 KB | Output is correct |
18 | Correct | 136 ms | 600 KB | Output is correct |
19 | Correct | 319 ms | 708 KB | Output is correct |
20 | Correct | 239 ms | 708 KB | Output is correct |
21 | Correct | 780 ms | 1028 KB | Output is correct |
22 | Correct | 837 ms | 1228 KB | Output is correct |
23 | Correct | 863 ms | 904 KB | Output is correct |
24 | Correct | 872 ms | 932 KB | Output is correct |
25 | Correct | 12 ms | 344 KB | Output is correct |
26 | Correct | 10 ms | 344 KB | Output is correct |
27 | Correct | 27 ms | 344 KB | Output is correct |
28 | Correct | 29 ms | 384 KB | Output is correct |
29 | Correct | 21 ms | 344 KB | Output is correct |
30 | Correct | 192 ms | 344 KB | Output is correct |
31 | Correct | 186 ms | 344 KB | Output is correct |
32 | Correct | 213 ms | 344 KB | Output is correct |
33 | Correct | 318 ms | 496 KB | Output is correct |
34 | Correct | 318 ms | 724 KB | Output is correct |
35 | Correct | 320 ms | 484 KB | Output is correct |
36 | Correct | 902 ms | 1256 KB | Output is correct |
37 | Correct | 930 ms | 1072 KB | Output is correct |
38 | Correct | 862 ms | 944 KB | Output is correct |
39 | Correct | 873 ms | 1072 KB | Output is correct |
40 | Correct | 863 ms | 984 KB | Output is correct |
41 | Correct | 907 ms | 1024 KB | Output is correct |
42 | Correct | 889 ms | 1012 KB | Output is correct |
43 | Correct | 781 ms | 1048 KB | Output is correct |
44 | Correct | 832 ms | 1008 KB | Output is correct |
45 | Correct | 13 ms | 344 KB | Output is correct |
46 | Correct | 10 ms | 344 KB | Output is correct |
47 | Correct | 28 ms | 344 KB | Output is correct |
48 | Correct | 24 ms | 344 KB | Output is correct |
49 | Correct | 22 ms | 344 KB | Output is correct |
50 | Correct | 196 ms | 452 KB | Output is correct |
51 | Correct | 206 ms | 704 KB | Output is correct |
52 | Correct | 211 ms | 448 KB | Output is correct |
53 | Correct | 323 ms | 504 KB | Output is correct |
54 | Correct | 294 ms | 752 KB | Output is correct |
55 | Correct | 320 ms | 848 KB | Output is correct |
56 | Correct | 854 ms | 928 KB | Output is correct |
57 | Correct | 819 ms | 896 KB | Output is correct |
58 | Correct | 866 ms | 992 KB | Output is correct |
59 | Correct | 850 ms | 928 KB | Output is correct |
60 | Correct | 826 ms | 1104 KB | Output is correct |
61 | Correct | 824 ms | 840 KB | Output is correct |
62 | Correct | 855 ms | 996 KB | Output is correct |
63 | Correct | 931 ms | 868 KB | Output is correct |
64 | Correct | 854 ms | 1360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 344 KB | Output is correct |
2 | Correct | 23 ms | 344 KB | Output is correct |
3 | Partially correct | 138 ms | 448 KB | Output is partially correct |
4 | Partially correct | 425 ms | 344 KB | Output is partially correct |
5 | Partially correct | 865 ms | 1140 KB | Output is partially correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 22 ms | 440 KB | Output is correct |
8 | Partially correct | 170 ms | 440 KB | Output is partially correct |
9 | Partially correct | 348 ms | 488 KB | Output is partially correct |
10 | Partially correct | 854 ms | 980 KB | Output is partially correct |
11 | Partially correct | 852 ms | 1324 KB | Output is partially correct |
12 | Partially correct | 832 ms | 1132 KB | Output is partially correct |
13 | Partially correct | 900 ms | 1140 KB | Output is partially correct |
14 | Correct | 5 ms | 596 KB | Output is correct |
15 | Correct | 11 ms | 344 KB | Output is correct |
16 | Correct | 56 ms | 344 KB | Output is correct |
17 | Partially correct | 96 ms | 424 KB | Output is partially correct |
18 | Partially correct | 199 ms | 692 KB | Output is partially correct |
19 | Partially correct | 314 ms | 720 KB | Output is partially correct |
20 | Partially correct | 293 ms | 512 KB | Output is partially correct |
21 | Correct | 9 ms | 344 KB | Output is correct |
22 | Correct | 9 ms | 344 KB | Output is correct |
23 | Correct | 22 ms | 344 KB | Output is correct |
24 | Correct | 26 ms | 344 KB | Output is correct |
25 | Correct | 34 ms | 344 KB | Output is correct |
26 | Partially correct | 180 ms | 708 KB | Output is partially correct |
27 | Partially correct | 227 ms | 600 KB | Output is partially correct |
28 | Partially correct | 214 ms | 344 KB | Output is partially correct |
29 | Partially correct | 353 ms | 600 KB | Output is partially correct |
30 | Partially correct | 310 ms | 480 KB | Output is partially correct |
31 | Partially correct | 324 ms | 480 KB | Output is partially correct |
32 | Correct | 9 ms | 344 KB | Output is correct |
33 | Correct | 9 ms | 344 KB | Output is correct |
34 | Correct | 23 ms | 344 KB | Output is correct |
35 | Correct | 33 ms | 344 KB | Output is correct |
36 | Correct | 20 ms | 344 KB | Output is correct |
37 | Partially correct | 218 ms | 600 KB | Output is partially correct |
38 | Partially correct | 188 ms | 600 KB | Output is partially correct |
39 | Partially correct | 212 ms | 592 KB | Output is partially correct |
40 | Partially correct | 338 ms | 592 KB | Output is partially correct |
41 | Partially correct | 325 ms | 708 KB | Output is partially correct |
42 | Partially correct | 348 ms | 960 KB | Output is partially correct |
43 | Partially correct | 827 ms | 896 KB | Output is partially correct |
44 | Partially correct | 850 ms | 1016 KB | Output is partially correct |
45 | Partially correct | 844 ms | 1316 KB | Output is partially correct |
46 | Partially correct | 840 ms | 928 KB | Output is partially correct |
47 | Partially correct | 839 ms | 1260 KB | Output is partially correct |
48 | Partially correct | 843 ms | 1508 KB | Output is partially correct |
49 | Partially correct | 875 ms | 1220 KB | Output is partially correct |
50 | Partially correct | 804 ms | 1392 KB | Output is partially correct |
51 | Partially correct | 850 ms | 1132 KB | Output is partially correct |
52 | Partially correct | 857 ms | 1104 KB | Output is partially correct |
53 | Partially correct | 866 ms | 1056 KB | Output is partially correct |
54 | Partially correct | 872 ms | 968 KB | Output is partially correct |
55 | Partially correct | 880 ms | 1064 KB | Output is partially correct |
56 | Partially correct | 912 ms | 788 KB | Output is partially correct |
57 | Partially correct | 888 ms | 808 KB | Output is partially correct |
58 | Partially correct | 901 ms | 936 KB | Output is partially correct |
59 | Partially correct | 849 ms | 1132 KB | Output is partially correct |
60 | Partially correct | 836 ms | 768 KB | Output is partially correct |
61 | Partially correct | 886 ms | 728 KB | Output is partially correct |
62 | Partially correct | 852 ms | 1072 KB | Output is partially correct |
63 | Partially correct | 872 ms | 1360 KB | Output is partially correct |
64 | Partially correct | 845 ms | 1328 KB | Output is partially correct |
65 | Partially correct | 867 ms | 968 KB | Output is partially correct |
66 | Partially correct | 902 ms | 1068 KB | Output is partially correct |
67 | Partially correct | 936 ms | 1024 KB | Output is partially correct |
68 | Partially correct | 855 ms | 1264 KB | Output is partially correct |
69 | Partially correct | 868 ms | 1024 KB | Output is partially correct |
70 | Partially correct | 906 ms | 932 KB | Output is partially correct |
71 | Partially correct | 869 ms | 1556 KB | Output is partially correct |
72 | Partially correct | 858 ms | 984 KB | Output is partially correct |
73 | Partially correct | 859 ms | 1316 KB | Output is partially correct |
74 | Partially correct | 921 ms | 1140 KB | Output is partially correct |
75 | Partially correct | 874 ms | 1236 KB | Output is partially correct |
76 | Partially correct | 862 ms | 1296 KB | Output is partially correct |
77 | Partially correct | 904 ms | 996 KB | Output is partially correct |
78 | Partially correct | 870 ms | 968 KB | Output is partially correct |
79 | Partially correct | 907 ms | 1320 KB | Output is partially correct |
80 | Partially correct | 870 ms | 1020 KB | Output is partially correct |
81 | Partially correct | 852 ms | 768 KB | Output is partially correct |
82 | Partially correct | 881 ms | 800 KB | Output is partially correct |