SlideShare a Scribd company logo
IJPC2015 B しりとり木
@sortreew
問題概要
半角英小文字からなるm個の文字列それぞれを
頂点とする根付き木で、
葉以外の頂点はちょうど2つの子を持つ
各親の文字列の末尾と子の文字列の先頭が一致する。
木の存在を判定・構成する。
制約はm<=10^4
判定
 まず、アルファベットの各文字を頂点としたグラフを考える。
 文字列はそれぞれ先頭文字から末尾文字への有向辺とする。
判定
根の先頭文字の頂点を𝑟𝑠とします。
 𝑟𝑠以外の全ての頂点の出次数は偶数であり、入次数*2>=出次
数を満たす。
 𝑟𝑠の出次数は奇数であり、入次数*2+1>=出次数を満たす。
 𝑟𝑠から入次数が0でない全ての頂点に到達できる。
 これらを満たせば”YES”そうでなければ”NO”を出力する。
証明
 十分条件であることは構成の過程で証明するとして、必要条
件となることを証明する。
証明
 𝑟𝑠以外の全ての頂点の出次数は偶数であり、入次数*2>=出次
数を満たす。
 頂点に入ってくる1本の辺に対し0または2つの辺(子)を持
てるが、入ってくる全ての辺に子を持たせても高々入次数*2
の辺しか使うことができない。なので、入次数*2<出次数の
とき出ていく辺が必ず余ってしまい、全ての辺を用いること
ができなくなる。
 また、出次数が奇数なら一度に用いられる辺の数が偶数なの
で辺が必ず余ってしまう。
証明
 𝑟𝑠の出次数は奇数であり、入次数*2+1>=出次数を満たす。
 根を作るのに出て行く辺を1つ使うので、他の頂点と比べ余
分に1つ辺を持っている必要がある。
証明
 𝑟𝑠から入次数が0でない全ての頂点に到達できる。
 自明(もし到達できないなら、到達できない頂点に入ってい
く辺を使うことができないので構成できない)
構成
幅優先で各頂点の子を選んでいく
子を選ぶ時、自分の頂点に到達できる頂点を優先し
て選べば良い。(深さ優先でO(頂点数^2)で調べるこ
とが出来る)
例:
{za,ab,ab,ac,ac,cd,cd,da}で根がzaのとき、bからaには到
達できないがcからaにはc->d->aで到達できるのでac
を優先する。
証明
これより入出次数が0の頂点は無視します。
まず、前提から入ってくる辺が残っている、全ての
頂点に到達できる。
存在すると判定されたとき、以下の操作を繰り返す。
1度も選ばれてない葉を1つ選ぶ。
その葉の頂点から出て行く辺がないなら、葉のまま
とする。
その葉の頂点に入ってくる辺がないなら、任意の2つ
の頂点を子とする。
証明
その葉の頂点に入ってくる辺がないなら、任意の2つ
の頂点を子とする。
その葉の頂点に入ってくる辺がないとき、前提より全
ての出て行く辺を使うことができる。この頂点にも戻
る必要がないので、この操作では「入ってくる辺が
残っている、全ての頂点に到達できる」状態を崩すこ
とはない
証明
操作の続き
どちらにも当てはまらないとき、「入ってくる辺が
残っている、全ての頂点に到達できる」ので選んだ
葉の頂点に到達できる葉が存在する。
もし選んだ葉自身が到達できるなら、子を選んだ葉
自身に到達できる頂点と適当な1つの頂点とする。
選んだ葉に再び到達できるので、 「入ってくる辺が
残っている、全ての頂点に到達できる」状態が崩れる
ことはない
証明
操作の続き
どちらにも当てはまらないとき、「入ってくる辺が
残っている、全ての頂点に到達できる」ので選んだ
葉の頂点に到達できる葉が存在する。
もし選んだ葉自身が到達できないなら、任意の2つの
頂点を子とする。
選んだ葉自身が到達できないならば、他の葉から選ん
だ葉の頂点に到達できるので、どれを選んでも到達で
きない点が現れることはない。
証明
これを繰り返しても辺が残っていてかつ到達不可能
な頂点が現れず、全ての辺を使い切る事ができるた
め、構成できない場合が存在しない。

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Ijpc2015 b しりとり木