답안 #965805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965805 2024-04-19T07:27:48 Z Darren0724 즐거운 행로 (APIO20_fun) C++17
10 / 100
9 ms 7516 KB
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
const int N=200005;
int cntid=0;
vector<int> adj[N],sz(N,1),pa(N),ans,dis(N);
priority_queue<pair<int,int>> pq[3];
void dfs(int k){
	for(int j:adj[k]){
		if(j==pa[k])continue;
		pa[j]=k;
		dfs(j);
		sz[k]+=sz[j];
	}
}
int cen(int k,int need){
	for(int j:adj[k]){
		if(j==pa[k])continue;
		if(sz[j]>=need)return cen(j,need);
	}
	return k;
}
void dfs1(int k,int pa){
	pq[cntid].push({dis[k],k});
	for(int j:adj[k]){
		if(j==pa)continue;
		dis[j]=dis[k]+1;
		dfs1(j,k);
	}
}
vector<int> createFunTour(int n, int q) {
  	//int H = hoursRequired(0, N - 1);
  	//int A = attractionsBehind(0, N - 1);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(hoursRequired(i,j)==1){
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		}
	}
	dfs(0);
	int c1=cen(0,(n+1)/2);
	for(int j:adj[c1]){
		dfs1(j,c1);
		cntid++;
	}
	int last=-1;
	for(int i=1;i<n;i++){
		pair<int,int> p={-1,-1};
		for(int j=0;j<cntid;j++){
			if(j==last)continue;
			p=max(p,make_pair((int)pq[j].size(),j));
		}
		last=p.second;
		auto [dis1,idx]=pq[p.second].top();
		pq[p.second].pop();
		ans.push_back(idx);
	}
	ans.push_back(c1);

  	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 3 ms 7484 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7512 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 3 ms 7484 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7512 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Incorrect 2 ms 7260 KB Tour is not fun
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Incorrect 2 ms 7260 KB Tour is not fun
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7256 KB Output is correct
8 Incorrect 9 ms 7516 KB Tour is not fun
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 3 ms 7484 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7512 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Incorrect 2 ms 7260 KB Tour is not fun
23 Halted 0 ms 0 KB -