<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>O'bin and the Chocolate Factory</title>
    <link>https://obinstory26.tistory.com/</link>
    <description></description>
    <language>ko</language>
    <pubDate>Fri, 7 Aug 2026 18:02:15 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>O'bin</managingEditor>
    <image>
      <title>O'bin and the Chocolate Factory</title>
      <url>https://tistory1.daumcdn.net/tistory/4958962/attach/12963268724543cb9644ed50823654d1</url>
      <link>https://obinstory26.tistory.com</link>
    </image>
    <item>
      <title>SQLD(SQL 개발자) 7시간 벼락치기 합격 후기</title>
      <link>https://obinstory26.tistory.com/199</link>
      <description>&lt;h3 data-ke-size=&quot;size23&quot;&gt;&lt;b&gt; 시험 정보&lt;/b&gt;&lt;/h3&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;SQL 자격증 종류 : SQLP(SQL 전문가), SQLD(SQL 개발자)&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;SQLD는 SQLP에 비해 난이도 낮음&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;응시 자격 조건이 없고 비교적 쉬운 난이도로 응시자 많음&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;b&gt;상세 설명&lt;/b&gt;은 아래 홈페이지 참고&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;(SQLD 응시자격, 시험 내용, 배점, 합격기준 등)&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.dataq.or.kr/www/sub/a_04.do&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.dataq.or.kr/www/sub/a_04.do&lt;/a&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size23&quot;&gt;&lt;b&gt; 베이스&lt;/b&gt;&lt;/h3&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #9d9d9d;&quot;&gt;벼락치기 전문가&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;IT 관련 학과 4학년&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;대학에서 데이터베이스 과목 수강&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;프로젝트에서 DB 사용 경험 O (MySql, MariaDB)&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size23&quot;&gt;&lt;b&gt; 학습방법&lt;/b&gt;&lt;/h3&gt;
&lt;p style=&quot;color: #333333; text-align: start;&quot; data-ke-size=&quot;size18&quot;&gt;&lt;span style=&quot;background-color: #f6e199;&quot;&gt;&lt;b&gt;유튜브 강의 &amp;rarr; 정리본 2회독 &amp;rarr; 중요부분 암기&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&lt;b&gt;준비기간 : &lt;span style=&quot;color: #ee2323;&quot;&gt;7시간&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size18&quot;&gt;합격점수 : &lt;b&gt;68점&lt;/b&gt;/100점 (60점 이상 합격)&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-filename=&quot;edited_스크린샷 2024-07-02 155614.png&quot; data-origin-width=&quot;689&quot; data-origin-height=&quot;420&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/sTpZh/btsI0zMU6aG/hyURK03dZLkghHqAML1iW0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/sTpZh/btsI0zMU6aG/hyURK03dZLkghHqAML1iW0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/sTpZh/btsI0zMU6aG/hyURK03dZLkghHqAML1iW0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FsTpZh%2FbtsI0zMU6aG%2FhyURK03dZLkghHqAML1iW0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;319&quot; height=&quot;368&quot; data-filename=&quot;edited_스크린샷 2024-07-02 155614.png&quot; data-origin-width=&quot;689&quot; data-origin-height=&quot;420&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size23&quot;&gt;&lt;b&gt; 후기&lt;/b&gt;&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;&lt;b&gt;IT 관련 학과 전공자 or DB 기초 개념 O&lt;/b&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;단시간 내 취득 가능&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;DB 지식 전혀 없는 &lt;b&gt;비전공자&lt;/b&gt;
&lt;ul style=&quot;list-style-type: disc;&quot; data-ke-list-type=&quot;disc&quot;&gt;
&lt;li&gt;하루 2-3시간 한두달 정도 공부하면 합격 가능&lt;/li&gt;
&lt;li&gt;&amp;uarr; 실제로 합격한 문과 친구 공부량&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/199</guid>
      <comments>https://obinstory26.tistory.com/199#entry199comment</comments>
      <pubDate>Wed, 6 Nov 2024 23:19:56 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 1753번 최단경로 (그래프, 다익스트라 )</title>
      <link>https://obinstory26.tistory.com/198</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1753&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/1753&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1326&quot; data-origin-height=&quot;807&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/Uvmle/btsJERknSgE/4yAJcOxOW2B9Xw0HhkBbm0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/Uvmle/btsJERknSgE/4yAJcOxOW2B9Xw0HhkBbm0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/Uvmle/btsJERknSgE/4yAJcOxOW2B9Xw0HhkBbm0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FUvmle%2FbtsJERknSgE%2F4yAJcOxOW2B9Xw0HhkBbm0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;588&quot; height=&quot;358&quot; data-origin-width=&quot;1326&quot; data-origin-height=&quot;807&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol1 )&amp;nbsp;&lt;/span&gt; 다익스트라 알고리즘으로 최단경로 탐색&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;33&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;34&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;35&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;36&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;37&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;38&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;39&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;heapq&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;dijkstra(s,&amp;nbsp;dis):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dis[s]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;heapq.heappush(q,&amp;nbsp;(&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;,&amp;nbsp;s))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;q:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cur_dis,&amp;nbsp;now&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;heapq.heappop(q)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;cur_dis&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;dis[now]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;continue&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;n,&amp;nbsp;weight&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;graph[now]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cost&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;cur_dis&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;weight&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;cost&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;dis[n]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dis[n]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;cost&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;heapq.heappush(q,&amp;nbsp;(cost,&amp;nbsp;n))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;V,&amp;nbsp;E&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;K&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;graph&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[]&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(V&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(E):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;u,&amp;nbsp;v,&amp;nbsp;w&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;graph[u].append((v,&amp;nbsp;w))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;최단경로&amp;nbsp;탐색&amp;nbsp;전&amp;nbsp;무한대(inf)로&amp;nbsp;초기화&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;dis&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[float(&lt;span style=&quot;color: #63a35c;&quot;&gt;'inf'&lt;/span&gt;)]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;(V&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;dijkstra(K,&amp;nbsp;dis)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;dis[&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;:]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;float(&lt;span style=&quot;color: #63a35c;&quot;&gt;'inf'&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(i)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;i가&amp;nbsp;무한대인&amp;nbsp;경우&amp;nbsp;경로&amp;nbsp;존재&amp;nbsp;x&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;else&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;'INF'&lt;/span&gt;)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;최단경로 문제의 다양한 상황과 조건에 따라 경로 탐색하는 방법을 더 연습해야겠다&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/198</guid>
      <comments>https://obinstory26.tistory.com/198#entry198comment</comments>
      <pubDate>Wed, 18 Sep 2024 23:33:17 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 1158번 요세푸스 문제 (deque, 수학, 시간복잡도)</title>
      <link>https://obinstory26.tistory.com/197</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1158&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/1158&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1074&quot; data-origin-height=&quot;693&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/bUZMxL/btsJDXrCuu4/OpIigngRpe7e9hhrhnPrz0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/bUZMxL/btsJDXrCuu4/OpIigngRpe7e9hhrhnPrz0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/bUZMxL/btsJDXrCuu4/OpIigngRpe7e9hhrhnPrz0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbUZMxL%2FbtsJDXrCuu4%2FOpIigngRpe7e9hhrhnPrz0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;494&quot; height=&quot;319&quot; data-origin-width=&quot;1074&quot; data-origin-height=&quot;693&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol1 )&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;deque을 이용한 풀이&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;from&lt;/span&gt;&amp;nbsp;collections&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;deque&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n,&amp;nbsp;k&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;q1&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;deque([i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;answer&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(k&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q1.append(q1.popleft())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer.append(q1.popleft())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;lt;'&lt;/span&gt;,end&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;answer,&amp;nbsp;sep&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;',&amp;nbsp;'&lt;/span&gt;,&amp;nbsp;end&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;gt;'&lt;/span&gt;)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;deque를 이용한 직관적 풀이&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그러나 시간복잡도가 O(N*k)로, k 크기 증가하면 비효율적&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol2 )&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt; 요세푸스 문제 수학적 풀이&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n,&amp;nbsp;k&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;people&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;list(&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,&amp;nbsp;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;answer&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;index&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;people:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;index&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;(index&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;k&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&amp;nbsp;%&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;len&lt;/span&gt;(people)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;answer.append(people.pop(index))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;lt;'&lt;/span&gt;,&amp;nbsp;end&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;answer,&amp;nbsp;sep&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;',&amp;nbsp;'&lt;/span&gt;,&amp;nbsp;end&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;gt;'&lt;/span&gt;)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;deque이 아니라 리스트 사용&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;인덱스를 계산해서 배열 값에 직접 접근&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;시간복잡도 O(N)으로 개선&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/197</guid>
      <comments>https://obinstory26.tistory.com/197#entry197comment</comments>
      <pubDate>Sun, 15 Sep 2024 23:52:57 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 5397번 키로거 (스택, 연결리스트(LinkedList))</title>
      <link>https://obinstory26.tistory.com/196</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/5397&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/5397&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1300&quot; data-origin-height=&quot;846&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/bdBfpz/btsJEPfeT9L/BRDac45yHkSTghvQCB9Z00/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/bdBfpz/btsJEPfeT9L/BRDac45yHkSTghvQCB9Z00/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/bdBfpz/btsJEPfeT9L/BRDac45yHkSTghvQCB9Z00/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbdBfpz%2FbtsJEPfeT9L%2FBRDac45yHkSTghvQCB9Z00%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;541&quot; height=&quot;352&quot; data-origin-width=&quot;1300&quot; data-origin-height=&quot;846&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol1 )&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt; stack을 이용한 풀이&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;t&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(t):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str1&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str2&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;input().rstrip():&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'-'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;str1:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str1.pop()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;lt;'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;str1:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str2.append(str1.pop())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;gt;'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;str2:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str1.append(str2.pop())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;else&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str1.append(i)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str1.extend(reversed(str2))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;.join(str1))&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;커서를 기준으로 두 개의 스택(str1, str2) 사용&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;커서 왼쪽 문자들은 str1에, 커서 오른쪽 문자들은 str2에 역순(스택 특성)으로 저장&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;최종 결과는 str1과 str2를 조합해 완성&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol 2 )&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt; &lt;b&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;연결리스트(linked list)를 이용한 &lt;/span&gt;풀이&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;33&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;34&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;35&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;36&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;37&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;38&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;39&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;40&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;41&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;42&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;43&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;44&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;45&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;46&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;47&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;48&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;49&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;50&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;51&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;52&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;53&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;54&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;55&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;56&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;57&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;58&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;59&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;60&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;61&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;62&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;63&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;64&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;65&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;66&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;67&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;68&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;69&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;class&lt;/span&gt;&amp;nbsp;Node:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;__init__(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;,&amp;nbsp;data&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;None&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.data&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;data&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.prev&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;None&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;None&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;class&lt;/span&gt;&amp;nbsp;LinkedList:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;__init__(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.head&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;Node()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;더미&amp;nbsp;헤드&amp;nbsp;노드&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.head&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;커서는&amp;nbsp;헤드에&amp;nbsp;저장&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;insert(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;,&amp;nbsp;data):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_node&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;Node(data)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_node.prev&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_node.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;.prev&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;new_node&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;new_node&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;new_node&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;delete(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.head:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;헤드에서는&amp;nbsp;삭제&amp;nbsp;불가&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.prev.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;.prev&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.prev&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.prev&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;삭제&amp;nbsp;후&amp;nbsp;커서&amp;nbsp;왼쪽으로&amp;nbsp;이동&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;move_left(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.head:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.prev&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;move_right(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.cursor.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;get_result(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;current&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.head.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;current:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result.append(current.data)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;current&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;current.&lt;span style=&quot;color: #a71d5d;&quot;&gt;next&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;.join(result)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;main():&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;t&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(t):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;linked_list&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;LinkedList()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;c&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;input().rstrip():&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;c&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'-'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;linked_list.delete()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;c&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;lt;'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;linked_list.move_left()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;c&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'&amp;gt;'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;linked_list.move_right()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;else&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;linked_list.insert(c)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(linked_list.get_result())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;__name__&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'__main__'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;main()&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: right; margin-top: -13px; margin-right: 5px; font-size: 9px; font-style: italic;&quot;&gt;&lt;a style=&quot;color: #e5e5e5text-decoration:none;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;이중 연결 리스트 사용해 커서 위치 기준으로 노드 삽입 또는 삭제&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;커서 이동은 연결리스트의 prev와 next 포인터로 처리&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt; stack과 linked list 비교 &amp;gt;&lt;/h4&gt;
&lt;table style=&quot;border-collapse: collapse; width: 100%; height: 139px;&quot; border=&quot;1&quot; data-ke-align=&quot;alignLeft&quot; data-ke-style=&quot;style8&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;height: 17px;&quot;&gt;
&lt;td style=&quot;width: 50%; text-align: center; height: 17px;&quot;&gt;stack&lt;/td&gt;
&lt;td style=&quot;width: 50%; text-align: center; height: 17px;&quot;&gt;linked list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;height: 122px;&quot;&gt;
&lt;td style=&quot;width: 50%; height: 122px;&quot;&gt;&lt;b&gt;구현 단순&lt;/b&gt;&lt;br /&gt;시간복잡도 O(1)로 빠름&lt;br /&gt;적은 메모리 사용&lt;br /&gt;&lt;b&gt;커서 이동 많을 경우 두 스택 사이 이동 자주 발생해 비효율적&lt;/b&gt;&lt;br /&gt;메모리 부족 발생 가능&lt;/td&gt;
&lt;td style=&quot;width: 50%; height: 122px;&quot;&gt;&lt;b&gt;커서 이동 시 O(1)로 빠름&lt;/b&gt;&lt;br /&gt;동적 메모리 관리&lt;br /&gt;특정 위치 연속 삽입/삭제 작업 효율 좋음&lt;br /&gt;&lt;b&gt;구현 복잡&lt;/b&gt;&lt;br /&gt;스택에 비해 포인터 저장 위한 추가 메모리 사용 필요&lt;br /&gt;cache hit rate 낮음&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/196</guid>
      <comments>https://obinstory26.tistory.com/196#entry196comment</comments>
      <pubDate>Sat, 14 Sep 2024 23:12:36 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 13549번 숨바꼭질 (메모리 초과, BFS, 최단거리)</title>
      <link>https://obinstory26.tistory.com/195</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/13549&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/13549&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1297&quot; data-origin-height=&quot;816&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/QMEkS/btsJvxzLObm/LxDXVoRAnmDDoWDthgi3WK/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/QMEkS/btsJvxzLObm/LxDXVoRAnmDDoWDthgi3WK/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/QMEkS/btsJvxzLObm/LxDXVoRAnmDDoWDthgi3WK/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FQMEkS%2FbtsJvxzLObm%2FLxDXVoRAnmDDoWDthgi3WK%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;532&quot; height=&quot;335&quot; data-origin-width=&quot;1297&quot; data-origin-height=&quot;816&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol1 )&lt;/span&gt;&lt;span&gt;&lt;span&gt; 나의 오답 - &lt;span style=&quot;color: #ee2323;&quot;&gt;메모리 초과&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;from&lt;/span&gt;&amp;nbsp;collections&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;deque&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n,&amp;nbsp;k&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;graph&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;deque([(n,&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;)])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;now,&amp;nbsp;time&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;graph.popleft()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;now&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;k:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(time)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;graph.append((now&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;2&lt;/span&gt;,&amp;nbsp;time))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;graph.append((now&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,&amp;nbsp;time&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;graph.append((now&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,&amp;nbsp;time&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;))&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;예제는 맞췄지만, 채점 시 &lt;b&gt;&lt;span style=&quot;color: #ee2323;&quot;&gt;메모리 초과&lt;/span&gt;&lt;/b&gt; 발생&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #ef5369;&quot;&gt;&lt;b&gt;틀린 이유&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;1. 중복 방문 체크 없음&lt;/b&gt; : 동일 위치 여러번 방문, 큐에 추가&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;2. 무한 이동&lt;/b&gt; : 이동 후 위치가 목표값인 k를 넘는 경우에도 체크하지 않고 무한 추가&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;3. 무한 루프 가능성&lt;/b&gt; : 이동 후 위치가 음수인 경우도 체크하지 않고 큐에 추가&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;4. 비효율적인 큐 처리&lt;/b&gt; : 순간이동의 경우 시간 증가하지 않음에도 큐 맨뒤에 추가&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&lt;span style=&quot;background-color: #99cefa;&quot;&gt;&amp;nbsp;sol2 )&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt; BFS로 탐색 - &lt;span style=&quot;color: #006dd7;&quot;&gt;정답&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;from&lt;/span&gt;&amp;nbsp;collections&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;deque&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;bfs(now,&amp;nbsp;target):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;deque([now])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time[now]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;방문&amp;nbsp;처리&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;q:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;q.popleft()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;현재&amp;nbsp;위치가&amp;nbsp;target(동생&amp;nbsp;위치)와&amp;nbsp;일치하면&amp;nbsp;시간&amp;nbsp;리턴&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;x&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;target:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;return&lt;/span&gt;&amp;nbsp;time[x]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;nx&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;(x&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,x&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,x&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;2&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;nx&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;limit&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;and&lt;/span&gt;&amp;nbsp;time[nx]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;nx&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;x:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time[nx]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;time[x]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;시간&amp;nbsp;증가하지&amp;nbsp;않았으므로&amp;nbsp;q&amp;nbsp;맨&amp;nbsp;앞&amp;nbsp;추가&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q.appendleft(nx)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;else&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;시간&amp;nbsp;1&amp;nbsp;증가,&amp;nbsp;q&amp;nbsp;맨&amp;nbsp;뒤에&amp;nbsp;추가&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time[nx]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;time[x]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;q.append(nx)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;현재&amp;nbsp;위치&amp;nbsp;p,&amp;nbsp;목표&amp;nbsp;위치&amp;nbsp;t&amp;nbsp;입력&amp;nbsp;받기&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;p,&amp;nbsp;t&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;limit&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;100001&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;time&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;limit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;방문&amp;nbsp;체크&amp;nbsp;및&amp;nbsp;시간&amp;nbsp;저장&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(bfs(p,&amp;nbsp;t))&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: right; margin-top: -13px; margin-right: 5px; font-size: 9px; font-style: italic;&quot;&gt;&lt;a style=&quot;color: #e5e5e5text-decoration:none;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;1번 오답 코드의 문제점들을 개선해&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- visited 배열로 방문 체크&lt;/b&gt;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- 이동 후 위치 범위 체크&lt;/b&gt;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;- 시간 증가하지 않는 순간이동은 큐 맨 앞, 나머지 시간 증가하는 이동은 큐 맨 뒤에 추가&lt;/b&gt;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;하여 효율적 메모리 사용 가능하도록 개선&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;문제에서 주어진 범위 조건들이 메모리 초과, 시간 초과 문제를 해결하기 위한 단서&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;방문 여부 확인 중요&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/195</guid>
      <comments>https://obinstory26.tistory.com/195#entry195comment</comments>
      <pubDate>Mon, 9 Sep 2024 13:16:57 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 3273번 두 수의 합 (정렬, 투 포인터)</title>
      <link>https://obinstory26.tistory.com/194</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/3273&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/3273&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1085&quot; data-origin-height=&quot;661&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/cPiZQY/btsJnM5HIyc/aph9qccJb3TYqlmpcJVdr0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/cPiZQY/btsJnM5HIyc/aph9qccJb3TYqlmpcJVdr0/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/cPiZQY/btsJnM5HIyc/aph9qccJb3TYqlmpcJVdr0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcPiZQY%2FbtsJnM5HIyc%2Faph9qccJb3TYqlmpcJVdr0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;481&quot; height=&quot;293&quot; data-origin-width=&quot;1085&quot; data-origin-height=&quot;661&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&amp;nbsp;sol 1 ) 배열에 인덱스 저장하고 값 비교해 계산&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;arr&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;list(map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split()))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;x&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;arr2&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;2000000&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arr2[arr[i]]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;i&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;arr2[x&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&amp;nbsp;arr[i]]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;i:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(cnt)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;입력을 arr에 받고, 각 원소를 인덱스로 하는 arr2 배열에 인덱스를 저장했다.&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;정답이었지만, 문제를 잘못 이해한 풀이고,&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;메모리 사용(불필요하게 큰 arr2 배열) 측면에서 비효율적인 코드&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;span style=&quot;color: #222222; text-align: start;&quot;&gt;시간복잡도 : O(n)&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;sol 2 ) 정렬과 투 포인터를 이용한 풀이&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;arr&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;list(map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split()))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;x&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;배열&amp;nbsp;정렬&amp;nbsp;후&amp;nbsp;포인터&amp;nbsp;양쪽&amp;nbsp;끝에&amp;nbsp;두&amp;nbsp;개&amp;nbsp;설정&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;arr.sort()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;left,&amp;nbsp;right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;,&amp;nbsp;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;while&lt;/span&gt;&amp;nbsp;left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;right:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;current_sum&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;arr[left]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;arr[right]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;current_sum&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;x:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;current_sum&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;x:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;else&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(cnt)&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;두 개의 포인터(left, right)를 정렬한 배열 양 쪽 끝에 두고&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;합이 x와 일치할때까지 이동하며 해당하는 값을 찾는 코드&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;시간복잡도가 O(n log n)으로 1번 코드보다 약간 느리지만 훨씬 적은 메모리 공간 사용&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;1번 코드보다 깔끔한 풀이&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/194</guid>
      <comments>https://obinstory26.tistory.com/194#entry194comment</comments>
      <pubDate>Mon, 2 Sep 2024 23:09:24 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 1068번 트리 (DFS)</title>
      <link>https://obinstory26.tistory.com/193</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1068&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/1068&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1277&quot; data-origin-height=&quot;761&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/kLH96/btsJdyLR4D4/iQWc29ZTcCb6bhGIluDmHk/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/kLH96/btsJdyLR4D4/iQWc29ZTcCb6bhGIluDmHk/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/kLH96/btsJdyLR4D4/iQWc29ZTcCb6bhGIluDmHk/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FkLH96%2FbtsJdyLR4D4%2FiQWc29ZTcCb6bhGIluDmHk%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;591&quot; height=&quot;352&quot; data-origin-width=&quot;1277&quot; data-origin-height=&quot;761&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&amp;nbsp;sol )&lt;span&gt; dfs를 이용한 리프 노드 탐색&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;33&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;34&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;dfs(node,&amp;nbsp;tree,&amp;nbsp;visited):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited[node]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #066de2;&quot;&gt;len&lt;/span&gt;(tree)):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;tree[i]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;node&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;and&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;visited[i]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dfs(i,&amp;nbsp;tree,&amp;nbsp;visited)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;tree&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;list(map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split()))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;del_node&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;visited&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color: #066de2;&quot;&gt;False&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;n&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;삭제할&amp;nbsp;노드와&amp;nbsp;그&amp;nbsp;자손들&amp;nbsp;방문&amp;nbsp;처리&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;dfs(del_node,&amp;nbsp;tree,&amp;nbsp;visited)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;리프&amp;nbsp;노드&amp;nbsp;계산&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;leaf_cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;visited[i]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;현재&amp;nbsp;노드가&amp;nbsp;리프&amp;nbsp;노드라고&amp;nbsp;일단&amp;nbsp;가정&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;is_leaf&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;j&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;노드&amp;nbsp;j의&amp;nbsp;부모&amp;nbsp;노드가&amp;nbsp;i이고&amp;nbsp;삭제되지&amp;nbsp;않은&amp;nbsp;경우(not&amp;nbsp;visited[j])&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;tree[j]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;and&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;visited[j]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;i는&amp;nbsp;리프노드가&amp;nbsp;아님&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;is_leaf&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;False&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;is_leaf:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;leaf_cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(leaf_cnt)&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: right; margin-top: -13px; margin-right: 5px; font-size: 9px; font-style: italic;&quot;&gt;&lt;a style=&quot;color: #e5e5e5text-decoration:none;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;DFS로 삭제 대상 노드의 자식 노드들을 모두 방문하고&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;방문하지 않은 노드 대상으로 리프 노드 여부를 검사해 그 수를 센다.&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;DFS가 그래프 전체 뿐만 아니라 부분에 대한 탐색을 할 때도 사용할 수 있다는 아이디어를 떠올리지 못했다.&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/193</guid>
      <comments>https://obinstory26.tistory.com/193#entry193comment</comments>
      <pubDate>Fri, 23 Aug 2024 10:55:52 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 1991번 트리 순회 (Node class, 트리, 재귀)</title>
      <link>https://obinstory26.tistory.com/192</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1991&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/1991&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1213&quot; data-origin-height=&quot;529&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/cOqKH7/btsI8mZOYgL/SY2GkVglSL4dkUwEopgM0K/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/cOqKH7/btsI8mZOYgL/SY2GkVglSL4dkUwEopgM0K/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/cOqKH7/btsI8mZOYgL/SY2GkVglSL4dkUwEopgM0K/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcOqKH7%2FbtsI8mZOYgL%2FSY2GkVglSL4dkUwEopgM0K%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;635&quot; height=&quot;277&quot; data-origin-width=&quot;1213&quot; data-origin-height=&quot;529&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&amp;nbsp;sol ) 재귀를 이용한 트리 탐색&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;33&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;34&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;35&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;36&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;37&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;38&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;39&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;40&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;41&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;42&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;43&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;44&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;45&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;46&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;47&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;48&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;49&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;50&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;51&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;class&lt;/span&gt;&amp;nbsp;Node:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;__init__(&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;,&amp;nbsp;item,&amp;nbsp;left,&amp;nbsp;right):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.item&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;item&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;left&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;self&lt;/span&gt;.right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;right&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;pre_order(node):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result.append(node.item)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pre_order(tree[node.left])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pre_order(tree[node.right])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;in_order(node):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;in_order(tree[node.left])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result.append(node.item)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;in_order(tree[node.right])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;post_order(node):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.left&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;post_order(tree[node.left])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;node.right&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'.'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;post_order(tree[node.right])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result.append(node.item)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;입력&amp;nbsp;처리&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input().strip())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;tree&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;{}&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i,&amp;nbsp;l,&amp;nbsp;r&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;input().strip().split()&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree[i]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;Node(i,&amp;nbsp;l,&amp;nbsp;r)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;전위&amp;nbsp;순회&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;result&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;pre_order(tree[&lt;span style=&quot;color: #63a35c;&quot;&gt;'A'&lt;/span&gt;])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;.join(result))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;중위&amp;nbsp;순회&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;result&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;in_order(tree[&lt;span style=&quot;color: #63a35c;&quot;&gt;'A'&lt;/span&gt;])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;.join(result))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;후위&amp;nbsp;순회&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;result&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;post_order(tree[&lt;span style=&quot;color: #63a35c;&quot;&gt;'A'&lt;/span&gt;])&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #63a35c;&quot;&gt;''&lt;/span&gt;.join(result))&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;line 4~8) 노드 클래스를 선언해 노드에 쉽게 접근할 수 있음&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;line 10~29) 재귀를 이용해 순회 구현하면 간단함&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;color: #222222; text-align: start;&quot; data-ke-size=&quot;size16&quot;&gt;트리, 재귀 문제 더 풀어보면서 구현 연습을 해야겠다.&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/192</guid>
      <comments>https://obinstory26.tistory.com/192#entry192comment</comments>
      <pubDate>Mon, 19 Aug 2024 17:18:22 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 9372번 상근이의 여행 (그래프, 트리)</title>
      <link>https://obinstory26.tistory.com/191</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/9372&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/9372&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1319&quot; data-origin-height=&quot;742&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/EfSFa/btsIYVULVjc/l0kJWGOxDcdRdvbLXhrkg0/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/EfSFa/btsIYVULVjc/l0kJWGOxDcdRdvbLXhrkg0/img.png&quot; data-alt=&quot;'&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/EfSFa/btsIYVULVjc/l0kJWGOxDcdRdvbLXhrkg0/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FEfSFa%2FbtsIYVULVjc%2Fl0kJWGOxDcdRdvbLXhrkg0%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;574&quot; height=&quot;323&quot; data-origin-width=&quot;1319&quot; data-origin-height=&quot;742&quot;/&gt;&lt;/span&gt;&lt;figcaption&gt;'&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;&amp;nbsp;sol ) DFS로 국가(노드) 탐색하여 비행 횟수 구하기&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;dfs(node,&amp;nbsp;cnt):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited[node]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;n&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;tree[node]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;visited[n]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cnt&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;dfs(n,&amp;nbsp;cnt&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;return&lt;/span&gt;&amp;nbsp;cnt&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;t&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(t):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n,&amp;nbsp;m&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[]&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color: #066de2;&quot;&gt;False&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;(n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(m):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;u,&amp;nbsp;v&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree[u].append(v)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree[v].append(u)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited[&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(dfs(&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;))&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;DFS로 풀 수 있는 쉬운 문제였다.&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;그래프(트리) 배열로 구현&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <category>프로그래밍/Python</category>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/191</guid>
      <comments>https://obinstory26.tistory.com/191#entry191comment</comments>
      <pubDate>Thu, 8 Aug 2024 10:43:22 +0900</pubDate>
    </item>
    <item>
      <title>백준_python 1967번 트리의 지름 (트리, DFS)</title>
      <link>https://obinstory26.tistory.com/190</link>
      <description>&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;문제&lt;span&gt;&amp;nbsp;&lt;/span&gt;링크&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;a href=&quot;https://www.acmicpc.net/problem/1967&quot; target=&quot;_blank&quot; rel=&quot;noopener&amp;nbsp;noreferrer&quot;&gt;https://www.acmicpc.net/problem/1967&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;imageblock alignLeft&quot; data-ke-mobileStyle=&quot;widthOrigin&quot; data-origin-width=&quot;1302&quot; data-origin-height=&quot;797&quot;&gt;&lt;span data-url=&quot;https://blog.kakaocdn.net/dn/oZ8qd/btsITuZignG/ZDUOLayxmj0Q0IZ8fwkcX1/img.png&quot; data-phocus=&quot;https://blog.kakaocdn.net/dn/oZ8qd/btsITuZignG/ZDUOLayxmj0Q0IZ8fwkcX1/img.png&quot;&gt;&lt;img src=&quot;https://blog.kakaocdn.net/dn/oZ8qd/btsITuZignG/ZDUOLayxmj0Q0IZ8fwkcX1/img.png&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FoZ8qd%2FbtsITuZignG%2FZDUOLayxmj0Q0IZ8fwkcX1%2Fimg.png&quot; onerror=&quot;this.onerror=null; this.src='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png'; this.srcset='//t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png';&quot; loading=&quot;lazy&quot; width=&quot;567&quot; height=&quot;347&quot; data-origin-width=&quot;1302&quot; data-origin-height=&quot;797&quot;/&gt;&lt;/span&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style=&quot;color: #000000; text-align: start;&quot; data-ke-size=&quot;size20&quot;&gt;&amp;lt;정답 코드&amp;gt;&lt;/h4&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&lt;b&gt;sol&lt;span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;) DFS를 이용한 최대 경로 길이 탐색&lt;/b&gt;&lt;/p&gt;
&lt;div class=&quot;colorscripter-code&quot; style=&quot;color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position: relative !important; overflow: auto;&quot;&gt;
&lt;table class=&quot;colorscripter-code-table&quot; style=&quot;margin: 0; padding: 0; border: none; background-color: #fafafa; border-radius: 4px;&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; data-ke-align=&quot;alignLeft&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 6px; border-right: 2px solid #e5e5e5;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; word-break: normal; text-align: right; color: #666; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;1&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;2&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;3&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;4&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;5&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;6&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;7&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;8&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;9&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;10&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;11&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;12&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;13&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;14&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;15&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;16&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;17&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;18&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;19&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;20&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;21&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;22&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;23&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;24&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;25&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;26&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;27&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;28&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;29&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;30&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;31&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;32&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;33&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;34&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;35&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;36&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;37&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;38&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;39&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;40&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;41&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;42&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;43&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;44&lt;/div&gt;
&lt;div style=&quot;line-height: 160%;&quot;&gt;45&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;padding: 6px 0; text-align: left;&quot;&gt;
&lt;div style=&quot;margin: 0; padding: 0; color: #010101; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; line-height: 160%;&quot;&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;import&lt;/span&gt;&amp;nbsp;sys&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;input&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;sys.stdin.readline&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;sys.setrecursionlimit(&lt;span style=&quot;color: #0099cc;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;5&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;dfs(node):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;global&amp;nbsp;max_dia,&amp;nbsp;tree,&amp;nbsp;visited&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;현재&amp;nbsp;노드에서&amp;nbsp;자식&amp;nbsp;노드로&amp;nbsp;가는&amp;nbsp;경로&amp;nbsp;중&amp;nbsp;가장&amp;nbsp;긴&amp;nbsp;경로&amp;nbsp;두개&amp;nbsp;저장&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long_one,&amp;nbsp;long_two&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;인접&amp;nbsp;노드&amp;nbsp;탐색&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;cn,&amp;nbsp;cw&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;tree[node]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;not&lt;/span&gt;&amp;nbsp;visited[cn]:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited[cn]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;path_len&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;dfs(cn)&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;cw&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;path_len&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;long_one:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long_one,&amp;nbsp;long_two&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;path_len,&amp;nbsp;long_one&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;elif&lt;/span&gt;&amp;nbsp;path_len&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;long_two:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long_two&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;path_len&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_dia&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;max(max_dia,&amp;nbsp;long_one&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&amp;nbsp;long_two)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;return&lt;/span&gt;&amp;nbsp;long_one&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;def&lt;/span&gt;&amp;nbsp;main():&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;global&amp;nbsp;tree,&amp;nbsp;visited,&amp;nbsp;max_dia&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;입력&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;(input())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[[]&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)]&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;tree[노드번호]&amp;nbsp;=&amp;nbsp;(부모or자식노드번호,&amp;nbsp;가중치)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;for&lt;/span&gt;&amp;nbsp;_&amp;nbsp;&lt;span style=&quot;color: #a71d5d;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;range&lt;/span&gt;(n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;):&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p,&amp;nbsp;c,&amp;nbsp;w&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;map(&lt;span style=&quot;color: #066de2;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;input().split())&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree[p].append((c,&amp;nbsp;w))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tree[c].append((p,&amp;nbsp;w))&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;[&lt;span style=&quot;color: #066de2;&quot;&gt;False&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;*&lt;/span&gt;&amp;nbsp;(n&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_dia&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #0099cc;&quot;&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;#&amp;nbsp;루트&amp;nbsp;노드에서&amp;nbsp;탐색&amp;nbsp;시작&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;visited[&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;]&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;True&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dfs(&lt;span style=&quot;color: #0099cc;&quot;&gt;1&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #066de2;&quot;&gt;print&lt;/span&gt;(max_dia)&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;if&lt;/span&gt;&amp;nbsp;__name__&amp;nbsp;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0086b3;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #a71d5d;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #63a35c;&quot;&gt;'__main__'&lt;/span&gt;:&lt;/div&gt;
&lt;div style=&quot;padding: 0 6px; white-space: pre; line-height: 160%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;main()&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: right; margin-top: -13px; margin-right: 5px; font-size: 9px; font-style: italic;&quot;&gt;&lt;a style=&quot;color: #e5e5e5text-decoration:none;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Colored by Color Scripter&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td style=&quot;vertical-align: bottom; padding: 0 2px 4px 0;&quot;&gt;&lt;a style=&quot;text-decoration: none; color: white;&quot; href=&quot;http://colorscripter.com/info#e&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span style=&quot;font-size: 9px; word-break: normal; background-color: #e5e5e5; color: white; border-radius: 10px; padding: 1px;&quot;&gt;cs&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-ke-size=&quot;size16&quot;&gt;&amp;nbsp;&lt;/p&gt;</description>
      <author>O'bin</author>
      <guid isPermaLink="true">https://obinstory26.tistory.com/190</guid>
      <comments>https://obinstory26.tistory.com/190#entry190comment</comments>
      <pubDate>Tue, 6 Aug 2024 11:06:58 +0900</pubDate>
    </item>
  </channel>
</rss>