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
3k
Grundy
yosupo
November 18, 2016
Tweet
Share
More Decks by yosupo
See All by yosupo
一般グラフの最大マッチング
yosupo
3
2k
Other Decks in Technology
See All in Technology
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
170
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
980
AGIについてChatGPTに聞いてみた
blueb
0
130
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
380
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.6k
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
4 Signs Your Business is Dying
shpigford
180
21k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
The Language of Interfaces
destraynor
154
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Done Done
chrislema
181
16k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
The Invisible Side of Design
smashingmag
298
50k
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))ʂ