SlideShare a Scribd company logo
Stanford Local 2007 <JOGGER> 풀이
https://algospot.com/judge/problem/read/JOGGER
http://ai.stanford.edu/~chuongdo/acm/2007/
문제설명
리프의 개수가 N(≤50)인 루트없는 트리가 주어지면,
각 리프 사이의 경로 중에서,
거리*R+내부 노드 개수*T의 최댓값을 구하는 문제.
문제설명
리프의 개수가 N(≤50)인 루트없는 트리가 주어지면,
각 리프 사이의 경로 중에서,
거리*R+내부 노드 개수*T의 최댓값을 구하는 문제.
O(N²)을 돌려도 충분한 쉬운 문제라 생각하고 input을 보면..
문제설명
9 1 5
0 8 22 16 16 13 24 14 11
8 0 20 14 14 11 22 12 9
22 20 0 12 12 11 22 12 23
16 14 12 0 4 5 16 6 17
16 14 12 4 0 5 16 6 17
13 11 11 5 5 0 13 3 14
24 22 22 16 16 13 0 14 25
14 12 12 6 6 3 14 0 15
11 9 23 17 17 14 25 15 0
0
??????
=
문제설명
9 1 5
0 8 22 16 16 13 24 14 11
8 0 20 14 14 11 22 12 9
22 20 0 12 12 11 22 12 23
16 14 12 0 4 5 16 6 17
16 14 12 4 0 5 16 6 17
13 11 11 5 5 0 13 3 14
24 22 22 16 16 13 0 14 25
14 12 12 6 6 3 14 0 15
11 9 23 17 17 14 25 15 0
0
리프의 개수가 주어지고, 리프끼리 거리가 주어짐.
트리 구조는 알아서 알아내라는 소리-_-;;
=
중요한 가정들
1. 내부 노드의 degree는 3 이상이다.
2. 각 경로의 거리는 1 이상이다.
이걸 기초로, 각 리프 사이의 경로 속에
숨어 있는 내부 노드의 개수를 알아내야!
Claim
리프 A, B사이의 내부 노드 개수는
A, B가 아닌 리프 L에 대해서
가능한 AL-BL값의 개수와 같다.
Proof
A P₁ BP₂ P₃
리프 A, B의 경로를 생각해 본다.
Proof
A P₁ BP₂ P₃
C
P₄
E
GF H
D
리프 A, B의 경로를 생각해 본다. 다른 리프들은 P부터 제각각 뻗어나간다.
P₁ P₃
C
P₄
E
F H
D
Proof
리프 A, B의 경로를 생각해 본다. 다른 리프들은 P부터 제각각 뻗어나간다.
어떤 리프 L에 대해서 AL=AP+PL, BL=BP+PL이다. 즉 AL-BL=AP-BP이다.
A BP₂
G
AG=AP₂+P₂G
BG=BP₂+P₂G
∴ AG-BG=AP₂-BP₂
Proof
어떤 노드 L에 대해서 AL-BL은 AB경로상에 뻗어간 점 P에 종속된다.
결국, 하나의 P에 대해서 AL-BL값은 모두 같다.
A P₁ BP₂ P₃
C
P₄
E
GF H
D
Proof
여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다.
1) 리프들만 순회해도 AB사이에 모든 P가 발견될까?
2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까?
Proof
여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다.
1) 리프들만 순회해도 AB사이에 모든 P가 발견될까?
2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까?
AB사이 노드 P는 내부노드이므로,
가정 (1)에 따라 degree가 3 이상이다.
즉 P에서 뻗어나가는 경로는 PA와 PB말고도 최소 하나는 존재한다.
이 경로를 따라 나오는 리프에서 P는 무조건 발견된다. 증명 끝!
Proof
여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다.
1) 리프들만 순회해도 AB사이에 모든 P가 발견될까?
2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까?
A P₁ BP₂ P₃
P₁과 P₂에서 AP-BP가 같다고 가정해본다.
AP₁-P₁B=AP₂-P₂B면, AP₁+P₂B=AP₂+P₁B이다.
이는 AB-P₁P₂=AB+P₁P₂이란 얘기다.
즉 P₁P₂=0이고 가정 (2)에 모순된다. 귀류법 증명 끝!
Conclusion
여기까지 증명이 되면 내부노드의 개수가 O(NlgN)에 계산이 되고
모든 리프를 순회해도 O(N³lgN)으로 넉넉하다.
20줄 코딩으로 AC가 가능함. 좋은 문제!

More Related Content

Featured

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
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Stanford Local 2007 - Jogger

  • 1. Stanford Local 2007 <JOGGER> 풀이 https://algospot.com/judge/problem/read/JOGGER http://ai.stanford.edu/~chuongdo/acm/2007/
  • 2. 문제설명 리프의 개수가 N(≤50)인 루트없는 트리가 주어지면, 각 리프 사이의 경로 중에서, 거리*R+내부 노드 개수*T의 최댓값을 구하는 문제.
  • 3. 문제설명 리프의 개수가 N(≤50)인 루트없는 트리가 주어지면, 각 리프 사이의 경로 중에서, 거리*R+내부 노드 개수*T의 최댓값을 구하는 문제. O(N²)을 돌려도 충분한 쉬운 문제라 생각하고 input을 보면..
  • 4. 문제설명 9 1 5 0 8 22 16 16 13 24 14 11 8 0 20 14 14 11 22 12 9 22 20 0 12 12 11 22 12 23 16 14 12 0 4 5 16 6 17 16 14 12 4 0 5 16 6 17 13 11 11 5 5 0 13 3 14 24 22 22 16 16 13 0 14 25 14 12 12 6 6 3 14 0 15 11 9 23 17 17 14 25 15 0 0 ?????? =
  • 5. 문제설명 9 1 5 0 8 22 16 16 13 24 14 11 8 0 20 14 14 11 22 12 9 22 20 0 12 12 11 22 12 23 16 14 12 0 4 5 16 6 17 16 14 12 4 0 5 16 6 17 13 11 11 5 5 0 13 3 14 24 22 22 16 16 13 0 14 25 14 12 12 6 6 3 14 0 15 11 9 23 17 17 14 25 15 0 0 리프의 개수가 주어지고, 리프끼리 거리가 주어짐. 트리 구조는 알아서 알아내라는 소리-_-;; =
  • 6. 중요한 가정들 1. 내부 노드의 degree는 3 이상이다. 2. 각 경로의 거리는 1 이상이다. 이걸 기초로, 각 리프 사이의 경로 속에 숨어 있는 내부 노드의 개수를 알아내야!
  • 7. Claim 리프 A, B사이의 내부 노드 개수는 A, B가 아닌 리프 L에 대해서 가능한 AL-BL값의 개수와 같다.
  • 8. Proof A P₁ BP₂ P₃ 리프 A, B의 경로를 생각해 본다.
  • 9. Proof A P₁ BP₂ P₃ C P₄ E GF H D 리프 A, B의 경로를 생각해 본다. 다른 리프들은 P부터 제각각 뻗어나간다.
  • 10. P₁ P₃ C P₄ E F H D Proof 리프 A, B의 경로를 생각해 본다. 다른 리프들은 P부터 제각각 뻗어나간다. 어떤 리프 L에 대해서 AL=AP+PL, BL=BP+PL이다. 즉 AL-BL=AP-BP이다. A BP₂ G AG=AP₂+P₂G BG=BP₂+P₂G ∴ AG-BG=AP₂-BP₂
  • 11. Proof 어떤 노드 L에 대해서 AL-BL은 AB경로상에 뻗어간 점 P에 종속된다. 결국, 하나의 P에 대해서 AL-BL값은 모두 같다. A P₁ BP₂ P₃ C P₄ E GF H D
  • 12. Proof 여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다. 1) 리프들만 순회해도 AB사이에 모든 P가 발견될까? 2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까?
  • 13. Proof 여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다. 1) 리프들만 순회해도 AB사이에 모든 P가 발견될까? 2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까? AB사이 노드 P는 내부노드이므로, 가정 (1)에 따라 degree가 3 이상이다. 즉 P에서 뻗어나가는 경로는 PA와 PB말고도 최소 하나는 존재한다. 이 경로를 따라 나오는 리프에서 P는 무조건 발견된다. 증명 끝!
  • 14. Proof 여기까지 떠올려도 코딩은 충분하지만, 증명할 게 남아있다. 1) 리프들만 순회해도 AB사이에 모든 P가 발견될까? 2) P₁, P₂, P₃…에 대해서 AP-BP가 유일할까? A P₁ BP₂ P₃ P₁과 P₂에서 AP-BP가 같다고 가정해본다. AP₁-P₁B=AP₂-P₂B면, AP₁+P₂B=AP₂+P₁B이다. 이는 AB-P₁P₂=AB+P₁P₂이란 얘기다. 즉 P₁P₂=0이고 가정 (2)에 모순된다. 귀류법 증명 끝!
  • 15. Conclusion 여기까지 증명이 되면 내부노드의 개수가 O(NlgN)에 계산이 되고 모든 리프를 순회해도 O(N³lgN)으로 넉넉하다. 20줄 코딩으로 AC가 가능함. 좋은 문제!