CodeForces 1103C. Johnny Solving

题目简述:给定简单(无自环、无重边)连通无向图$G = (V, E), 1 \leq n = |V| \leq 2.5 \times 10^5, 1 \leq m = |E| \leq 5 \times 10^5$,保证任意节点的度数$\geq 3$。给定参数$1 \leq k \leq n$,要求完成以下任务之一:

1. 找到一条包含至少$\frac n k$个节点的简单路径。

2. 找到$k$个简单环,使得

2.1. 每个环包含少于$\frac n k$个节点,且包含的节点个数不得被$3$整除;

2.2. 每个环都存在一个代表节点,这个节点不在其他环中出现。

解:code

考虑图$G$的DFS树$T$。

1. 若$T$中存在深度$\geq \frac n k$的节点(根节点深度为$1$),则找到了一条包含至少$\frac n k$个节点的简单路径,完成任务1。

2. 不然(即,树$T$的深度$< \frac n k$),$T$存在至少$k$个叶节点(设$T$有$x$个叶节点,则

$$n = |V| \leq \sum_{v \text{ is a leaf of } T} \text{depth}(v) < x \frac n k, $$

从而$x > k$)。我们可以通过其中$k$个叶节点构造$k$个满足条件的简单环。

设$v \in V$为$T$的某个叶节点,注意到$v$在$G$中的度数$\geq 3$,故存在两个不同的节点$x, y \in V$,他们都不是$v$的父节点且$(v, x), (v, y) \in E$。则$x$和$y$均是$v$在$T$中的祖先(DFS树的性质)。不妨设$\text{depth}(x) > \text{depth}(y)$。

考虑以下三个环:

a) $v, \text{father}(v), \dots, x$,长度为$l_a = \text{depth}(v)-\text{depth}(x)+1$;

b) $v, \text{father}(v), \dots, y$,长度为$l_b = \text{depth}(v)-\text{depth}(y)+1$;

c) $v, x, \text{father}(x), \dots, y$,长度为$l_c = \text{depth}(x)-\text{depth}(y)+2$。

这三个环的长度均$ < \frac n k$,且不可均为3的倍数(设环a和环b长度均为3的倍数,则环c的长度$ l_c = l_b-l_a+2 \equiv 2 \pmod 3 $不为3的倍数)。完成任务2。

原文地址:https://www.cnblogs.com/TinyWong/p/10348575.html

时间: 2024-08-30 18:05:23

CodeForces 1103C. Johnny Solving的相关文章

Johnny Solving CodeForces - 1103C (构造,图论)

大意: 无向图, 无重边自环, 每个点度数>=3, 要求完成下面任意一个任务 找一条结点数不少于n/k的简单路径 找k个简单环, 每个环结点数小于n/k, 且不为3的倍数, 且每个环有一个特殊点$x$, $x$只属于这一个环 任选一棵生成树, 若高度>=n/k, 直接完成任务1, 否则对于叶子数一定不少于k, 而叶子反向边数>=2, 一定可以构造出一个环 #include <iostream> #include <algorithm> #include <c

CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq \frac nk\) 的路径: 找出 \(k\) 个简单环,满足长度不是 \(3\) 的倍数,并且每个环至少存在一个点不在别的环中. 很显然题目并不是要你随便挑一种回答方式开始单独研究.最有可能的情况是两种回答方式可以替补. 如果我们随便作出原图的一棵生成树,如果最长的路径长度 \(\geq \f

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #534 (Div. 2)

A. Splitting into digits 题意:把一个数分成若干[1,9]之间的数字,使得这些数尽量相同. 思路:输出n个1. #include<bits/stdc++.h> #define CLR(a,b) memset(a,,sizeof(a)) using namespace std; typedef long long ll; const int maxn=100010; int main(){ int n; cin>>n; int flag=0,j=2; prin

Codeforces 798D Mike and distribution - 贪心

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, 

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

CodeForces 706C dp

C - Hard problem Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 706C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he as

Codeforces 528D Fuzzy Search(FFT)

题目 Source http://codeforces.com/problemset/problem/528/D Description Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings cons

第二十次codeforces竞技结束 #276 Div 2

真是状况百出的一次CF啊-- 最终还Unrated了,你让半夜打cf 的我们如何释怀(中途茫茫多的人都退场了)--虽说打得也不好-- 在这里写一下这一场codeforces的解题报告,A-E的 题目及AC代码,部分题目有简单评析,代码还算清晰,主要阅读代码应该不难以理解. Questions about problems # Author Problem When Question Answer       2014-11-05 21:24:38 Announcement General ann