Submission #1065581

# Submission time Handle Problem Language Result Execution time Memory
1065581 2024-08-19T09:35:19 Z ReLice Longest Trip (IOI23_longesttrip) C++17
5 / 100
930 ms 1592 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define ins insert
#define fr first
#define sc second
#define vll vector<ll>
#define sz size()
using namespace std;

const ll N = 260;
const ll inf = 1e9 + 7;

vector<vll> g(N);
ll d[N],p[N];
bool vis[N];

void dfs(ll v){
	vis[v] = 1;
	for(auto i : g[v]){
		if(d[i] != inf || (!vis[i] && d[i] < d[v] + 1))continue;
		
		p[i] = v;
		d[i] = d[v] + 1;
		
		dfs(i);
	}
	vis[v] = 0;
}

void cl(){
	for(ll i=0;i<N;i++){
		d[i] = inf;
		p[i] = i;
	}
}

pair<ll,ll> find(){
	ll mx = -1, x = 0;
	
	for(ll i=0;i<N;i++){
		if(d[i] != inf && d[i] > mx){
			mx = d[i];
			x = i;
		}
	}
	
	return {mx, x};
}

vector<int> longest_trip(int n, int D){
	ll i,j;
	
	for(i=0;i<n;i++) g[i].clear();
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(are_connected({i},{j})){
				g[i].pb(j);
				g[j].pb(i);
			}
		}
	}
	
	ll rt = 0, ans = 0;
	
	for(i=0;i<1;i++){
		cl();
		
		d[i] = 0;
		dfs(i);
		
		auto [mx, x] = find();
		
		if(mx < ans){
			mx = ans;
			rt = i;
		}
	}
	
	cl();
	
	d[rt] = 0;
	dfs(rt);
	
	auto [mx, x] = find();
	
	vll v;
	while(x != rt){
		v.pb(x);
		x = p[x];
	}
	v.pb(rt);
	
	return v;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 221 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 27 ms 344 KB Output is correct
3 Correct 173 ms 344 KB Output is correct
4 Correct 396 ms 592 KB Output is correct
5 Correct 777 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 162 ms 600 KB Output is correct
4 Correct 389 ms 724 KB Output is correct
5 Correct 814 ms 1260 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 27 ms 344 KB Output is correct
3 Correct 147 ms 344 KB Output is correct
4 Correct 383 ms 728 KB Output is correct
5 Correct 930 ms 1008 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 157 ms 600 KB Output is correct
9 Correct 293 ms 488 KB Output is correct
10 Correct 791 ms 876 KB Output is correct
11 Correct 899 ms 1264 KB Output is correct
12 Correct 824 ms 1592 KB Output is correct
13 Correct 865 ms 1044 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Partially correct 137 ms 344 KB Output is partially correct
4 Partially correct 391 ms 976 KB Output is partially correct
5 Partially correct 887 ms 1204 KB Output is partially correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -