Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Grundy
Search
yosupo
November 18, 2016
Technology
1
3.1k
Grundy
yosupo
November 18, 2016
Tweet
Share
More Decks by yosupo
See All by yosupo
一般グラフの最大マッチング
yosupo
3
2.1k
Other Decks in Technology
See All in Technology
Backboneとしてのtimm2025
yu4u
4
1.6k
どこで動かすか、誰が動かすか 〜 kintoneのインフラ基盤刷新と運用体制のシフト 〜
ueokande
0
190
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
190
microCMS 最新リリース情報(microCMS Meetup 2025)
microcms
0
120
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
30k
退屈なことはDevinにやらせよう〜〜Devin APIを使ったVisual Regression Testの自動追加〜
kawamataryo
3
750
DuckDB-Wasmを使って ブラウザ上でRDBMSを動かす
hacusk
1
110
実践アプリケーション設計 ②トランザクションスクリプトへの対応
recruitengineers
PRO
4
570
「AI2027」を紐解く ― AGI・ASI・シンギュラリティ
masayamoriofficial
0
110
自社製CMSからmicroCMSへのリプレースがプロダクトグロースを加速させた話
nextbeatdev
0
150
人と組織に偏重したEMへのアンチテーゼ──なぜ、EMに設計力が必要なのか/An antithesis to the overemphasis of people and organizations in EM
dskst
6
640
Evolution on AI Agent and Beyond - AGI への道のりと、シンギュラリティの3つのシナリオ
masayamoriofficial
0
190
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
53
8.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Git: the NoSQL Database
bkeepers
PRO
431
65k
Docker and Python
trallard
45
3.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
900
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
We Have a Design System, Now What?
morganepeng
53
7.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Rails Girls Zürich Keynote
gr2m
95
14k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Transcript
Grundy @yosupot
ҎԼͷΛߟ͑·͢ NMลͷDAG͕༩͑ΒΕΔɻ1ʹ͕ۨஔ͍ͯ͋Δ A͞ΜͱB͞Μ͕ަޓʹۨΛಈ͔͢ɻ ۨลͰͭͳ͕ͬͨʹಈ͔ͤͯɺಈ͔ͤͳ͘ͳͬͨΒ ෛ͚ Ͳ͕ͬͪউͭʁ
ղ๏ dfsͰղ͘ ಈ͔ͤΔʹʮޙʯͱॻ͔Ε͕ͨ͋Εʮઌʯ ͳ͚Εʮޙʯͱॻ͘ 0ʹʮઌʯͱॻ͔ΕΕઌखඞউ ʮޙʯͱॻ͔ΕΕޙखඞউ
ྫ ޙ ޙ ઌ ઌ 1
ҎԼͷΛߟ͑·͢ NMลͷDAG͕Kछྨ༩͑ΒΕΔɻͦΕͧΕͷάϥϑͷ 1ʹ͕ۨஔ͍ͯ͋Δ A͞ΜͱB͞Μ͕ަޓʹɺͲΕ͔ͷάϥϑͷۨΛಈ͔͢ɻ ۨลͰͭͳ͕ͬͨʹಈ͔ͤͯɺಈ͔ͤͳ͘ͳͬͨΒ ෛ͚ Ͳ͕ͬͪউͭʁ
ղ๏ ࣮ෳͷάϥϑ1ͭͷάϥϑʹ·ͱΊΒΕΔ (άϥϑ1ͷۨͷҐஔ, άϥϑ2ͷۨͷҐஔ, …, άϥϑKͷۨͷ Ґஔ)Λͱͯ͠దʹลΛషΔ ͜ͷάϥϑͰಉ͡Α͏ʹdfs͕Ͱ͖Δ ܭࢉྔO((N+M)^K)
O((N+M)^K)ʂʁ N=M=5000ͱͯ͠(N+M)^Kʁ K=1 → 10000 K=2 → 1,000,000,000 K=3 →
10,000,000,000,000 K=100 → 10^400
ͬͱޮྑ͘ܭࢉͰ͖ͳ͍͔ʁ ·ͣK=2ͷ߹Λߟ͑Δ
ߟ 2ͭͷάϥϑ͕ͲͪΒޙखউͪͳΒɺશମͰޙखউͪ 2ͭͷάϥϑ͕(ઌखউͪ + ޙखউͪ)ͳΒɺશମͰઌख উͪ ͩͬͨΒɺ(ઌखউͪ + ઌखউͪ)ͷ߹ʁ ࣮શମͰઌखউͪʹͳΔྫޙखউͪʹͳΔྫ࡞ΕΔ
Ұҙʹఆ·Βͳ͍ ʴ ʴ ʹ ʹ ઌखউͪ ޙखউͪ
Ͳ͏͢Δʁ άϥϑΛʮઌखউͪʯͱʮޙखউͪʯʹ·ͱΊΔ͜ͱͰ ͖ͳ͍ Ͱ2छྨఘΊΔͱͯ͠ɺԿछྨ͔ʹάϥϑΛྨ͢Δ ͜ͱͰ͖ͳ͍ͷ͔ʁ
(άϥϑA + άϥϑX)ͷউഊͱ(άϥϑB + άϥϑX)ͷউഊ ͕ɺXʹ͔͔ΘΒ͍ͣ࣌͠ɺάϥϑA,BΛʮຊ࣭తʹ͠ ͍ʯͱ͢Δ (ޙखউͪ+ޙखউͪ)ͱ(ޙखউͪ+ઌखউͪ)Ұҙʹఆ·Δ ͷͰɺޙखউͪͲ͏͠ʮຊ࣭తʹ͍͠ʯ ͳͷͰɺઌखউͪͲ͏͠ʮຊ࣭తʹ͍͠ʯͷͰʁͱ
Ծఆࣦͯ͠ഊͨ͠ͷ͕ࠓͷঢ়ଶ ઌखউͪͷάϥϑ1छྨʹ·ͱΊΔ͜ͱͰ͖ͳ͍ʂ
ͱ͜ΖͰ ͖ͬࣔͨ͞͠Α͏ʹɺҎԼͷ2ͭͷάϥϑ͘͠ͳ͍ ͳͥʁ
ͱ͜ΖͰ ࠨͷάϥϑޙखউͪʹ͔͠ߦ͚ͳ͍͕ɺӈͷάϥϑޙखউͪͱઌखউͪͷ ྆ํʹߦ͚Δ ޙखউͪͱઌखউ͕ͪ྆ํඋΘΓ࠷ڧʹݟ͑Δ(ӈͷάϥϑͷํ͕ࣗ༝͕ߴͦ ͏)
͡Ό͋ ͜ͷάϥϑߋʹ࠷ڧͳͷͰʁ
͡Ό͋ ͜ͷάϥϑߋʹ࠷ڧͳͷͰʁ
࣮ શDAGͲ͏͠ޓ͍ʹ͘͠ͳ͍͜ͱ͕ࣔͤΔ(TODO) ͳͷͰগͳ͘ͱ༗ݶछྨͰͳ͍
΄΅શDAGʁ શDAGಉ࢜ҟͳΔ͜ͱ͕Θ͔ͬͨ ͡Ό͋શDAGʹ1ݸΛՃ͑ͨͷʁ શDAGͷ͏͍͔ͪͭ͘ͷʹɺ1͔Βล͕ੜ͍͑ͯ ΔɺΑ͏ͳάϥϑ
ྫ͑ ͜Ε1͔Β1, 3ͷDAGʹߦ͚ΔΑ͏ͳάϥϑ
ྫ͑ ͜Ε1͔Β1, 3ͷશDAGʹߦ͚ΔΑ͏ͳάϥϑ ͜Ε2ͷશDAGͱ͍͠
ͳͥʁ 3ͷશDAGʹߦͬͯɺ༗རʹͳΔ͜ͱͳ͍ ͳͥͳΒɺ૬ख࣍ͷखͰ2ͷશDAGҠಈͰ͖ΔͨΊ ݁ہɺ1ͷશDAGߦ͔͘͠ͳ͍ͨΊɺ2ͷશDAGͱຊ࣭తʹ͍͠ ͜ͷลΛͬͯ༗རʹͳΔ͜ͱͳ͍
΄΅શDAG {a, b, c, …}ʹߦ͚Δͱ͢Δͱɺ=ʮ{a, b, c, …}ʹ ग़ͯ͜ͳ͍࠷খͷਖ਼ʯͷશDAGͱຊ࣭తʹ͍͠ ྫ͑{1,
3, 4, 5}ʹߦ͚ΔͳΒ=2 ͳ͔ͥͱ͍͏ͱɺ3,4,5ͷͲΕʹߦ͘ͷɺ࣍ͷखͰ૬खʹ2 ʹ͞ΕΔͷͰɺ༗རʹͳΕͳ͍
Ұൠʹ ઌड़ͷنଇΑΓؼೲతʹɺશͯͷάϥϑશDAGͷͲΕ͔ͱ ຊ࣭తʹ͍͠ =kͷશDAGͱຊ࣭తʹ͍͠άϥϑΛlevel (k-1)ͷάϥ ϑͱݺͿ (0-indexedͰͳ͍ͱ৭ʑ໘) άϥϑͷlevel࠶ؼతʹܭࢉͰ͖ΔͨΊɺO(N+M)ͰٻΊΒΕΔ
݁ہ (aͷશDAG + bͷશDAG)ͱมܗͰ͖Δ ͜Εͷඞউఆ؆୯(a = b͔൱͔) O(N+M)
K=3 K=3ͷ߹ʁ ࠷ॳͷ۪ղΛࢥ͍ग़͢ͱɺෳݸͷάϥϑ1ݸͷάϥϑʹ·ͱΊΒΕΔ ͦͯ͠ɺk=2ͳΒશͯͷάϥϑશDAGมܗͰ͖Δ͜ͱΛ͏ (άϥϑA + άϥϑB + άϥϑC)= {άϥϑA
+ (άϥϑBͱάϥϑCΛ·ͱΊͨͷ)}= (શDAG + άϥϑB + άϥϑC) Αͬͯk=2ͷ࣌ͱಉ͡نଇͰશDAGมܗͯ͠Α͍
K=4 K=4ͷ߹ʁ (άϥϑA + άϥϑB + άϥϑC + άϥϑD)= {άϥϑA+(άϥϑBͱάϥϑCͱάϥϑDΛ·ͱΊͨͷ)}=
(શDAG + άϥϑB + άϥϑC + άϥϑD)
݁ہ (શDAG + શDAG + … + શDAG)ʹมܗͰ͖Δ ͜ͷඞউఆʁ(࣮NimήʔϜͱ͍͏༗໊ͳܗͷήʔϜʹͳ͍ͬͯΔ…) (શDAG
+ શDAG + … + શDAG)= {(શDAGͱશDAGΛ·ͱΊͨͷ) + (K-2ݸͷશDAGΛ·ͱΊͨͷ)}= ʹมܗͰ͖Δ ͱ͜ΖͰɺK=2ͳͷͰ(શDAGͱશDAGΛ·ͱΊͨͷ)શDAGมܗͰ͖Δ ͭ·Γɺ(શDAGͱશDAGΛ·ͱΊͨͷ)ΛશDAGʹมܗͰ͖ΔͱɺK-1ʹؼ ணͰ͖Δ
શDAG + શDAG (શDAGͱશDAGΛ·ͱΊͨͷ)ͱ͍͠શDAGͷ ʁ ࣮ɺ(a+1)ͱ(b+1)Λ·ͱΊΔͱɺ(a xor b)+1 ͱ͘͠ͳΔ(TODOઆ໌) ͭ·Γɺlevel
aͱlevel bΛ߹͢Δͱɺlevel (a xor b)ʹͳΔ (͜Ε͕0-indexedʹͨ͠ཧ༝)
ղ๏ ͱ͍͏͜ͱɺlevel a + b + …ͳΒɺlevel (a xor b
xor …) ͱ͍͠ ͜Ε͕0͔Ͳ͏͔ผ͢Ε͑ O(K(N+M))ʂ