Submission #1065582

# Submission time Handle Problem Language Result Execution time Memory
1065582 2024-08-19T09:36:57 Z ReLice Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 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(auto i : [0, n/2, n/3, n/3*2, n - 1]){
		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;
}



Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:67:16: error: expected identifier before numeric constant
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                ^
longesttrip.cpp:67:17: error: expected ']' before ',' token
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                 ^
      |                 ]
longesttrip.cpp: In lambda function:
longesttrip.cpp:67:17: error: expected '{' before ',' token
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:67:20: warning: right operand of comma operator has no effect [-Wunused-value]
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                   ~^~
longesttrip.cpp:67:25: warning: right operand of comma operator has no effect [-Wunused-value]
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                        ~^~
longesttrip.cpp:67:32: warning: right operand of comma operator has no effect [-Wunused-value]
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                             ~~~^~
longesttrip.cpp:67:40: error: 'begin' was not declared in this scope
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                                        ^
longesttrip.cpp:67:40: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from longesttrip.cpp:2:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
longesttrip.cpp:67:40: error: 'end' was not declared in this scope
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |                                        ^
longesttrip.cpp:67:40: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from longesttrip.cpp:2:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
longesttrip.cpp:67:41: error: expected ')' before ']' token
   67 |  for(auto i : [0, n/2, n/3, n/3*2, n - 1]){
      |     ~                                   ^
      |                                         )
longesttrip.cpp:67:41: error: expected primary-expression before ']' token
longesttrip.cpp:65:13: warning: unused variable 'ans' [-Wunused-variable]
   65 |  ll rt = 0, ans = 0;
      |             ^~~