Submission #1081432

# Submission time Handle Problem Language Result Execution time Memory
1081432 2024-08-30T04:52:09 Z LCJLY The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
231 ms 14560 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);
	}
	
	dfs(safe,-1);
	
	vector<int>ans(n);
	for(int x=1;x<=n;x++){
		if(x==safe){
			ans[x-1]=2;
		}
		else if(sz[x]<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);
	}
	
	dfs(1,-1);
	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);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2820 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 231 ms 13936 KB Partially correct
2 Partially correct 215 ms 14452 KB Partially correct
3 Partially correct 106 ms 14560 KB Partially correct
4 Partially correct 110 ms 13980 KB Partially correct
5 Incorrect 190 ms 14424 KB Not correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 87 ms 8080 KB Partially correct
2 Partially correct 83 ms 8448 KB Partially correct
3 Incorrect 67 ms 8316 KB Not correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2820 KB Partially correct
2 Partially correct 231 ms 13936 KB Partially correct
3 Partially correct 215 ms 14452 KB Partially correct
4 Partially correct 106 ms 14560 KB Partially correct
5 Partially correct 110 ms 13980 KB Partially correct
6 Incorrect 190 ms 14424 KB Not correct
7 Halted 0 ms 0 KB -