Submission #1040545

# Submission time Handle Problem Language Result Execution time Memory
1040545 2024-08-01T07:08:59 Z 정희우(#10998) The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
180 ms 14204 KB
#include <vector>
#include "incursion.h"
#include <cstdio>
#include<iostream>
#include<algorithm>

using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;
using vintp = vector<intp>;

const int MAX_N=45010;

int n;
vintp eg[MAX_N];
int sz[MAX_N];
vint val;
int isleaf=0;

bool compe(const intp &e1,const intp &e2)
{
	return e1.second>e2.second;
}

int fillsz(int v,int p)
{
	sz[v]=1;
	for(auto &e : eg[v])
		if(e.first!=p)
		{
			e.second=fillsz(e.first,v);
			sz[v]+=e.second;
		}
	for(auto &e : eg[v])
		if(e.first==p)
			e.second=n-sz[v];
	sort(eg[v].begin(),eg[v].end(),compe);
	return sz[v];
}

bool ismid(int v)
{
	int mx=0;
	for(auto e : eg[v])
		mx=max(mx,e.second);
	int c=0;
	for(auto e : eg[v])
		if(e.second==mx)c++;
	return c>=2;
}

void dfs(int v,int p)
{
	if(ismid(v))
	{
		val[v-1]=isleaf;
	}
	else if(p==0)
	{
		val[v-1]=0;
	}
	else
	{
		int mx=0;
		for(auto e : eg[v])
			mx=max(mx,e.second);
		for(auto e : eg[v])
			if(e.first==p)
				val[v-1]=(e.second==mx);
	}
	for(auto e : eg[v])
		if(e.first!=p)
			dfs(e.first,v);
}

vint mark(vintp F, int safe)
{
  	n=F.size()+1;
	for(int i=1;i<=n;i++)
		eg[i].clear();
	for(int i=0;i<n-1;i++)
	{
		int u=F[i].first,v=F[i].second;
		eg[u].push_back({v,0});
		eg[v].push_back({u,0});
	}
	val.resize(n);
	fillsz(safe,0);
	isleaf=(eg[safe].size()<=1);
	dfs(safe,0);
	return val;
}

bool checkleaf(int v,int p)
{
	if(isleaf==-1)return false;
	int flag=1;
	for(auto e : eg[v])
		if(e.first!=p && eg[e.first].size()>1)flag=0;
	if(flag==0)return false;
	if(isleaf==0)return true;
	for(auto e : eg[v])
		if(e.first!=p)
		{
			if(visit(e.first)==0)return true;
			visit(v);
		}
	return false;
}

void calc(int v,int p,int t)
{
	if(ismid(v))
	{
		isleaf=t;
		if(checkleaf(v,p))
			return;
		for(auto e : eg[v])
			if(e.first!=p)
			{
				int nt=visit(e.first);
				if(nt==0)
				{
					calc(e.first,v,nt);
					return;
				}
				visit(v);
			}
		return;
	}
	if(checkleaf(v,p))
		return;
	if(t==1)return calc(eg[v][0].first,v,visit(eg[v][0].first));
	if(t==0 && eg[v].size()<=1)return;
	int nt;
	if(eg[v][1].first!=p)
	{
		nt=visit(eg[v][1].first);
		if(nt==0)
		{
			calc(eg[v][1].first,v,nt);
			return;
		}
		visit(v);
	}
	nt=visit(eg[v][2].first);
	if(nt==0)
	{
		calc(eg[v][2].first,v,nt);
		return;
	}
	visit(v);
}

void locate(vintp F, int curr, int t)
{
	n=F.size()+1;
	for(int i=1;i<=n;i++)
		eg[i].clear();
	for(int i=0;i<n-1;i++)
	{
		int u=F[i].first,v=F[i].second;
		eg[u].push_back({v,0});
		eg[v].push_back({u,0});
	}
	fillsz(curr,0);
	isleaf=-1;
	calc(curr,0,t);
	return;
}

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 Correct 2 ms 2820 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 13024 KB Correct
2 Correct 170 ms 13032 KB Correct
3 Incorrect 104 ms 14204 KB Not correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8716 KB Correct
2 Correct 64 ms 8860 KB Correct
3 Correct 70 ms 8860 KB Correct
4 Correct 75 ms 11548 KB Correct
5 Correct 107 ms 11276 KB Correct
6 Correct 137 ms 11612 KB Correct
7 Correct 73 ms 8584 KB Correct
8 Correct 72 ms 8588 KB Correct
9 Correct 64 ms 8620 KB Correct
10 Correct 70 ms 8584 KB Correct
11 Correct 74 ms 8592 KB Correct
12 Correct 72 ms 8560 KB Correct
13 Correct 70 ms 8608 KB Correct
14 Correct 46 ms 7068 KB Correct
15 Correct 40 ms 7216 KB Correct
16 Correct 70 ms 8572 KB Correct
17 Correct 69 ms 8532 KB Correct
18 Correct 72 ms 8624 KB Correct
19 Correct 66 ms 8604 KB Correct
20 Correct 49 ms 7232 KB Correct
21 Correct 44 ms 7216 KB Correct
22 Correct 47 ms 7204 KB Correct
23 Correct 49 ms 7344 KB Correct
24 Correct 48 ms 7084 KB Correct
25 Correct 50 ms 7340 KB Correct
26 Correct 72 ms 8688 KB Correct
27 Correct 72 ms 8576 KB Correct
28 Correct 67 ms 8576 KB Correct
29 Correct 67 ms 8572 KB Correct
30 Correct 67 ms 8840 KB Correct
31 Correct 81 ms 8536 KB Correct
32 Correct 79 ms 8612 KB Correct
33 Correct 65 ms 8820 KB Correct
34 Correct 75 ms 8588 KB Correct
35 Correct 70 ms 8528 KB Correct
36 Correct 81 ms 9064 KB Correct
37 Correct 63 ms 8560 KB Correct
38 Correct 62 ms 8580 KB Correct
39 Correct 80 ms 8832 KB Correct
40 Correct 68 ms 9080 KB Correct
41 Correct 68 ms 8604 KB Correct
42 Correct 71 ms 8604 KB Correct
43 Correct 67 ms 8800 KB Correct
44 Correct 73 ms 8940 KB Correct
45 Correct 76 ms 8572 KB Correct
46 Correct 74 ms 8572 KB Correct
47 Correct 64 ms 8860 KB Correct
48 Correct 65 ms 8812 KB Correct
49 Correct 78 ms 8692 KB Correct
50 Correct 68 ms 8604 KB Correct
51 Correct 61 ms 8576 KB Correct
52 Correct 75 ms 8732 KB Correct
53 Correct 75 ms 8728 KB Correct
54 Correct 69 ms 8808 KB Correct
55 Correct 77 ms 8548 KB Correct
56 Correct 69 ms 8832 KB Correct
57 Correct 79 ms 8612 KB Correct
58 Correct 74 ms 8864 KB Correct
59 Incorrect 68 ms 8868 KB Not correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2820 KB Correct
2 Correct 180 ms 13024 KB Correct
3 Correct 170 ms 13032 KB Correct
4 Incorrect 104 ms 14204 KB Not correct
5 Halted 0 ms 0 KB -