답안 #852233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852233 2023-09-21T13:09:16 Z Wansur 가장 긴 여행 (IOI23_longesttrip) C++17
25 / 100
11 ms 3672 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=1e3+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);
			}
		}
	}
	int a=t[0],b=t[1];
	if((int)g[a].size()>(int)g[b].size()){
		return g[a];
	}
	else{
		return g[b];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 2648 KB Output is correct
4 Correct 6 ms 2904 KB Output is correct
5 Correct 6 ms 3160 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 2648 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 7 ms 2648 KB Output is correct
11 Correct 6 ms 3216 KB Output is correct
12 Correct 6 ms 3244 KB Output is correct
13 Correct 6 ms 2844 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 6 ms 600 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 6 ms 2648 KB Output is correct
19 Correct 6 ms 2648 KB Output is correct
20 Correct 6 ms 3164 KB Output is correct
21 Correct 7 ms 3456 KB Output is correct
22 Correct 6 ms 2912 KB Output is correct
23 Correct 6 ms 3160 KB Output is correct
24 Correct 6 ms 3160 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 7 ms 2696 KB Output is correct
31 Correct 7 ms 2952 KB Output is correct
32 Correct 7 ms 2700 KB Output is correct
33 Correct 6 ms 2904 KB Output is correct
34 Correct 6 ms 2904 KB Output is correct
35 Correct 7 ms 3160 KB Output is correct
36 Correct 7 ms 2904 KB Output is correct
37 Correct 9 ms 3416 KB Output is correct
38 Correct 7 ms 2992 KB Output is correct
39 Correct 10 ms 3008 KB Output is correct
40 Correct 7 ms 3416 KB Output is correct
41 Correct 8 ms 2964 KB Output is correct
42 Correct 9 ms 3424 KB Output is correct
43 Correct 10 ms 3480 KB Output is correct
44 Correct 9 ms 3672 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 6 ms 344 KB Output is correct
47 Correct 5 ms 344 KB Output is correct
48 Correct 6 ms 596 KB Output is correct
49 Correct 5 ms 344 KB Output is correct
50 Correct 7 ms 2692 KB Output is correct
51 Correct 7 ms 2692 KB Output is correct
52 Correct 7 ms 2952 KB Output is correct
53 Correct 6 ms 2836 KB Output is correct
54 Correct 6 ms 2904 KB Output is correct
55 Correct 7 ms 2904 KB Output is correct
56 Correct 6 ms 3416 KB Output is correct
57 Correct 7 ms 3316 KB Output is correct
58 Correct 11 ms 3160 KB Output is correct
59 Correct 8 ms 3064 KB Output is correct
60 Correct 7 ms 3672 KB Output is correct
61 Correct 7 ms 2944 KB Output is correct
62 Correct 8 ms 2948 KB Output is correct
63 Correct 8 ms 2904 KB Output is correct
64 Correct 8 ms 3196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -