답안 #1081442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081442 2024-08-30T04:57:13 Z LCJLY The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
215 ms 15480 KB
#include "incursion.h"
#include <bits/stdc++.h>
//#include "sample_grader.cpp"
using namespace std;

//#define int long long 
//#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;

int n;
vector<int>adj[45005];
int sz[45005];
int pp[45005];
int child[45005];

void dfs(int index, int par){
	sz[index]=1;
	for(auto it:adj[index]){
		if(it==par) continue;
		dfs(it,index);
		pp[it]=index;
		child[index]=it;
		sz[index]+=sz[it];
	}
}

vector<int>mark(vector<pair<int, int>> F, int safe){
	n=F.size()+1;
	for(int x=0;x<n-1;x++){
		adj[F[x].first].push_back(F[x].second);
		adj[F[x].second].push_back(F[x].first);
	}
	
	for(int x=1;x<=n;x++){
		if(adj[x].size()==1){
			dfs(x,-1);
			break;
		}
	}
	
	vector<int>ans(n);
	for(int x=1;x<=n;x++){
		if(x==safe){
			ans[x-1]=2;
		}
		else if(sz[x]-1<n-sz[x]){
			ans[x-1]=0;
		}		
		else ans[x-1]=1;
	}
	return ans;
}


//visit()
void locate(vector<pair<int, int>> F, int curr, int t){
	n=F.size()+1;
	for(int x=0;x<=n;x++){
		adj[x].clear();
		sz[x]=0;
	}
	for(int x=0;x<n-1;x++){
		adj[F[x].first].push_back(F[x].second);
		adj[F[x].second].push_back(F[x].first);
	}
	
	for(int x=1;x<=n;x++){
		if(adj[x].size()==1){
			dfs(x,-1);
			break;
		}
	}
	int cur=curr;
	
	//potentially start at centroid
	int take=-1;
	for(int i=0;i<2;i++){
		if(t==2){
			return;
		}
		else if(t==1){
			//go to smaller side
			if(sz[cur]-1>=n-sz[cur]){
				t=visit(pp[cur]);
				take=cur;
				cur=pp[cur];
			}
			else{
				t=visit(child[cur]);
				take=cur;
				cur=child[cur];
			}
		}
		else{
			if(sz[cur]-1<n-sz[cur]){
				t=visit(pp[cur]);
				take=cur;
				cur=pp[cur];
			}
			else{
				t=visit(child[cur]);
				take=cur;
				cur=child[cur];
			}
		}
	}

	while(t!=2){
		if(t==0){
			//go to larger one
			if(pp[cur]!=take&&sz[cur]-1<n-sz[cur]){
				t=visit(pp[cur]);
				take=cur;
				cur=pp[cur];
			}
			else{
				t=visit(child[cur]);
				take=cur;
				cur=child[cur];
			}
		}
		else if(t==1){
			//go to smaller one
			if(pp[cur]!=take&&sz[cur]-1>=n-sz[cur]){
				t=visit(pp[cur]);
				take=cur;
				cur=pp[cur];
			}
			else{
				t=visit(child[cur]);
				take=cur;
				cur=child[cur];
			}
		}
	}
}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2816 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 201 ms 15480 KB Partially correct
2 Incorrect 215 ms 15244 KB Not correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 80 ms 8320 KB Partially correct
2 Incorrect 75 ms 8292 KB Not correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2816 KB Partially correct
2 Partially correct 201 ms 15480 KB Partially correct
3 Incorrect 215 ms 15244 KB Not correct
4 Halted 0 ms 0 KB -