Submission #1069814

# Submission time Handle Problem Language Result Execution time Memory
1069814 2024-08-22T09:08:55 Z Muhammad_Aneeq Longest Trip (IOI23_longesttrip) C++17
40 / 100
926 ms 1620 KB
#pragma GCC optimize("O2")
#include <vector>
#include <set>
#include "longesttrip.h"
using namespace std;
int const MAXN=256;
vector<int>nei[MAXN]={};
vector<int>ans;
vector<int>cur;
bool vis[MAXN]={};
void dfs(int u,int p=-1)
{
	vis[u]=1;
	cur.push_back(u);
	bool w=0;
	for (auto i:nei[u])
	{
		if (vis[i])
			continue;
		w=1;
		dfs(i,u);
	}
	if (cur.size()>ans.size())
		ans=cur;
	cur.pop_back();
}
vector<int> sol(int N)
{
	for (int i=0;i<N;i++)
	{
		if (!vis[i])
			dfs(i);
	}
	return ans;
}
vector<int> longest_trip(int N, int D)
{
	ans={};
	cur={};
	for (int i=0;i<N;i++)
		nei[i]={},vis[i]=0;
	for (int i=0;i<N;i++)
		for (int j=i+1;j<N;j++)
			if (are_connected({i},{j}))
				nei[i].push_back(j),nei[j].push_back(i);
	if (D==1)
	{
		return sol(N);
	}
	for (int i=0;i<N;i++)
	{
		for (int j=0;j<N;j++)
			vis[j]=0;
		dfs(i);
	}
	return ans;
}

Compilation message

longesttrip.cpp: In function 'void dfs(int, int)':
longesttrip.cpp:15:7: warning: variable 'w' set but not used [-Wunused-but-set-variable]
   15 |  bool w=0;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 221 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 159 ms 448 KB Output is correct
4 Correct 421 ms 344 KB Output is correct
5 Correct 869 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 128 ms 344 KB Output is correct
4 Correct 452 ms 700 KB Output is correct
5 Correct 868 ms 1216 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 141 ms 344 KB Output is correct
9 Correct 338 ms 968 KB Output is correct
10 Correct 853 ms 696 KB Output is correct
11 Correct 871 ms 1068 KB Output is correct
12 Correct 847 ms 1016 KB Output is correct
13 Correct 894 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 151 ms 344 KB Output is correct
4 Correct 402 ms 436 KB Output is correct
5 Correct 867 ms 588 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 26 ms 344 KB Output is correct
8 Correct 140 ms 344 KB Output is correct
9 Correct 341 ms 344 KB Output is correct
10 Correct 820 ms 884 KB Output is correct
11 Correct 881 ms 1116 KB Output is correct
12 Correct 898 ms 1220 KB Output is correct
13 Correct 876 ms 916 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 15 ms 344 KB Output is correct
16 Correct 48 ms 344 KB Output is correct
17 Correct 85 ms 344 KB Output is correct
18 Correct 138 ms 444 KB Output is correct
19 Correct 301 ms 704 KB Output is correct
20 Correct 296 ms 848 KB Output is correct
21 Correct 866 ms 1620 KB Output is correct
22 Correct 858 ms 796 KB Output is correct
23 Correct 837 ms 1220 KB Output is correct
24 Correct 783 ms 900 KB Output is correct
25 Correct 14 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 26 ms 344 KB Output is correct
28 Correct 32 ms 344 KB Output is correct
29 Correct 15 ms 344 KB Output is correct
30 Correct 192 ms 344 KB Output is correct
31 Correct 221 ms 592 KB Output is correct
32 Correct 207 ms 672 KB Output is correct
33 Correct 326 ms 460 KB Output is correct
34 Correct 316 ms 704 KB Output is correct
35 Correct 291 ms 344 KB Output is correct
36 Correct 809 ms 1412 KB Output is correct
37 Correct 890 ms 1232 KB Output is correct
38 Correct 795 ms 940 KB Output is correct
39 Correct 847 ms 1156 KB Output is correct
40 Correct 791 ms 1200 KB Output is correct
41 Correct 832 ms 692 KB Output is correct
42 Correct 821 ms 712 KB Output is correct
43 Correct 861 ms 1204 KB Output is correct
44 Correct 787 ms 1300 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 10 ms 344 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 22 ms 344 KB Output is correct
49 Correct 20 ms 344 KB Output is correct
50 Correct 195 ms 344 KB Output is correct
51 Correct 200 ms 344 KB Output is correct
52 Correct 217 ms 424 KB Output is correct
53 Correct 281 ms 596 KB Output is correct
54 Correct 306 ms 464 KB Output is correct
55 Correct 274 ms 680 KB Output is correct
56 Correct 887 ms 852 KB Output is correct
57 Correct 882 ms 1244 KB Output is correct
58 Correct 850 ms 1180 KB Output is correct
59 Correct 926 ms 1100 KB Output is correct
60 Correct 902 ms 1344 KB Output is correct
61 Correct 863 ms 1224 KB Output is correct
62 Correct 868 ms 720 KB Output is correct
63 Correct 853 ms 952 KB Output is correct
64 Correct 832 ms 1196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Partially correct 147 ms 340 KB Output is partially correct
4 Partially correct 388 ms 720 KB Output is partially correct
5 Partially correct 882 ms 768 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -