Submission #1315019

#TimeUsernameProblemLanguageResultExecution timeMemory
1315019PlayVoltzLongest Trip (IOI23_longesttrip)C++20
Compilation error
0 ms0 KiB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

vector<int> longest_trip(int n, int d){
	if (d==3){
		vector<int> ans;
		for (int i=0; i<n; ++i)ans.pb(i);
		return ans;
	}
	if (d==2){
		deque<int> ans(1, 0);
		int done=1;
		if (are_connected({0}, {1}))ans.pb(1);
		else ans.pb(2), done=2;
		for (int i=1; i<n; ++i)if (i!=done){
			if (are_connected({i}, {ans.back()}))ans.pb(i);
			else ans.push_front(i);
		}
		vector<int> res;
		for (auto a:ans)res.pb(a);
		return res;
	}
	int res=1;
	deque<int> ans(1, 0);
	set<int> s;
	for (int i=1; i<n; ++i)s.insert(i);
	int loop=100;
	while (loop--){
		vector<int> temp;
		for (int i:s){
			if (are_connected({i}, {ans.back()}))ans.pb(i), temp.pb(i);
			else if (are_connected({i}, {ans[0]}))ans.push_front(i), temp.pb(i);
		}
		for (auto a:temp)s.erase(a);
	}
	vector<int> res;
	for (auto a:ans)res.pb(a);
	return res;
}

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:43:21: error: conflicting declaration 'std::vector<int> res'
   43 |         vector<int> res;
      |                     ^~~
longesttrip.cpp:30:13: note: previous declaration as 'int res'
   30 |         int res=1;
      |             ^~~
longesttrip.cpp:5:12: error: request for member 'push_back' in 'res', which is of non-class type 'int'
    5 | #define pb push_back
      |            ^~~~~~~~~
longesttrip.cpp:44:29: note: in expansion of macro 'pb'
   44 |         for (auto a:ans)res.pb(a);
      |                             ^~
longesttrip.cpp:45:16: error: could not convert 'res' from 'int' to 'std::vector<int>'
   45 |         return res;
      |                ^~~
      |                |
      |                int