Submission #1040520

# Submission time Handle Problem Language Result Execution time Memory
1040520 2024-08-01T06:50:26 Z 정희우(#10998) The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
176 ms 14208 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!=v)
			{
				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,curr,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 176 ms 12956 KB Correct
2 Correct 173 ms 13008 KB Correct
3 Incorrect 111 ms 14208 KB Not correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8804 KB Correct
2 Correct 77 ms 8840 KB Correct
3 Correct 84 ms 8696 KB Correct
4 Correct 81 ms 11404 KB Correct
5 Correct 134 ms 11516 KB Correct
6 Correct 134 ms 11608 KB Correct
7 Correct 72 ms 8644 KB Correct
8 Correct 76 ms 8568 KB Correct
9 Correct 70 ms 8612 KB Correct
10 Correct 73 ms 8540 KB Correct
11 Correct 67 ms 8604 KB Correct
12 Correct 71 ms 8768 KB Correct
13 Correct 70 ms 8516 KB Correct
14 Correct 54 ms 7084 KB Correct
15 Correct 56 ms 6960 KB Correct
16 Correct 57 ms 8512 KB Correct
17 Correct 68 ms 8608 KB Correct
18 Correct 62 ms 8572 KB Correct
19 Correct 68 ms 8556 KB Correct
20 Correct 54 ms 7216 KB Correct
21 Correct 55 ms 7324 KB Correct
22 Correct 54 ms 7328 KB Correct
23 Correct 55 ms 7224 KB Correct
24 Correct 52 ms 7340 KB Correct
25 Correct 53 ms 7208 KB Correct
26 Correct 76 ms 9048 KB Correct
27 Correct 82 ms 8772 KB Correct
28 Correct 67 ms 8820 KB Correct
29 Correct 73 ms 8536 KB Correct
30 Correct 78 ms 8592 KB Correct
31 Correct 71 ms 8660 KB Correct
32 Correct 73 ms 8584 KB Correct
33 Correct 81 ms 8696 KB Correct
34 Correct 78 ms 8804 KB Correct
35 Correct 73 ms 8608 KB Correct
36 Correct 76 ms 8992 KB Correct
37 Correct 72 ms 8572 KB Correct
38 Correct 69 ms 8816 KB Correct
39 Correct 72 ms 8572 KB Correct
40 Correct 69 ms 8604 KB Correct
41 Correct 74 ms 8616 KB Correct
42 Correct 64 ms 8712 KB Correct
43 Correct 68 ms 8804 KB Correct
44 Correct 68 ms 8608 KB Correct
45 Correct 68 ms 8688 KB Correct
46 Correct 69 ms 8996 KB Correct
47 Correct 72 ms 8836 KB Correct
48 Correct 78 ms 8744 KB Correct
49 Correct 76 ms 8560 KB Correct
50 Correct 66 ms 8676 KB Correct
51 Correct 78 ms 8432 KB Correct
52 Correct 69 ms 8616 KB Correct
53 Correct 75 ms 8620 KB Correct
54 Correct 76 ms 8852 KB Correct
55 Correct 71 ms 8644 KB Correct
56 Correct 62 ms 8832 KB Correct
57 Correct 79 ms 8620 KB Correct
58 Correct 69 ms 8796 KB Correct
59 Incorrect 69 ms 9080 KB Not correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2820 KB Correct
2 Correct 176 ms 12956 KB Correct
3 Correct 173 ms 13008 KB Correct
4 Incorrect 111 ms 14208 KB Not correct
5 Halted 0 ms 0 KB -