답안 #852230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852230 2023-09-21T13:05:57 Z Wansur 가장 긴 여행 (IOI23_longesttrip) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
#include<bits/stdc++.h>
#define f first
#define s second
#define ent '\n'

using namespace std;
typedef long long ll;

const int mx=2e2+12;

vector<int> g[mx];
int was[mx][mx];

bool are_connected(std::vector<int> A, std::vector<int> B);

int  ask(int a,int b){
	if(!was[a][b]){
		was[a][b]=was[b][a]=(int)are_connected({a},{b})+1;
	}
	return was[a][b]-1;
}

std::vector<int> longest_trip(int n, int d){
	vector<int> ans;
	for(int i=0;i<n;i++){
		g[i].clear();
		for(int j=0;j<n;j++){
			was[i][j]=0;
		}
	}
	srand(time(0));
	vector<int> t;
	for(int i=0;i<n;i++){
		g[i].push_back(i);
		t.push_back(i);
	}
	while(t.size()>2){
		int a=t[0],b=t[1],c=t[2];
		vector<pair<int,int>> d;
		d.push_back({a,b});
		d.push_back({a,c});
		d.push_back({b,c});
		random_shuffle(d.begin(),d.end());
		int v,u;
		if(ask(d[0].f,d[0].s)){
			v=d[0].f,u=d[0].s;
		}
		else if(ask(d[1].f,d[1].s)){
			v=d[1].f,u=d[1].s;
		}
		else{
			v=d[2].f,u=d[2].s;
		}
		reverse(g[v].begin(),g[v].end());
		for(int x:g[u]){
			g[v].push_back(x);
		}
		g[u].clear();
		int x=g[v][0];
		if(x!=v){
			for(int to:g[v]){
				g[x].push_back(to);
			}
			g[v].clear();
		}
		t.clear();
		for(int i=0;i<n;i++){
			if((int)g[i].size()>0){
				t.push_back(i);
			}
		}
	}
	if((int)g[a].size()>(int)g[b].size()){
		return g[a];
	}
	else{
		return g[b];
	}
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:74:12: error: 'a' was not declared in this scope
   74 |  if((int)g[a].size()>(int)g[b].size()){
      |            ^
longesttrip.cpp:74:29: error: 'b' was not declared in this scope
   74 |  if((int)g[a].size()>(int)g[b].size()){
      |                             ^