TCO10 Marathon Round 3
Subgraph Isomorphismããåé¡
æ«å®8ä½ã ãã©ãããããã·ã¹ãã ãã¹ãã§é ä½ãè¶
å
¥ãæ¿ããã¨æãããã®ã§å®å¿åºæ¥ãªã
ééã§ãã¦ãã¨ãããªã
æ¦ç¥ä¸éè¦ãªãã¨
ã¹ã³ã¢ã絶対è©ä¾¡ãªã®ã§ãç¹ã稼ããã¨ããã§ä¸æ°ã«ç¨¼ããªãã¨ãããªã
é£ããã±ã¼ã¹ã¯é å¼µã£ã¦ã20ã40ç¹ã¨ããããããã®ç¹æ°ããã¨ããªãã®ã«å¯¾ããç°¡åãªã±ã¼ã¹ã¯300ç¹ä»¥ä¸åãã
forumæ
å ±ã ã¨ï¼ã±ã¼ã¹ã§2600ç¹ã¨ã£ã人ã¾ã§ããã¨ãâ¦
ãã®ãã¨ã«çµç¤ã§æ°ã¥ããã®ã§ããã£ããã¯ç¹æ°ä½ãã®ãããããã¨ããã®ãããã¦ãç¹æ°é«ããã¤ãããã«é«ãããããã«é å¼µã£ã
åºæ¬çãªæ¹é
åºæ¬çã«ã¯å
¨æ¢ç´¢ããã ã
ã¾ãæåã«ãH(å°ããæ¹ã®ã°ã©ã)ã®é ç¹ã®é çªãåºå®ãããã®é ã«æ¢ç´¢ãè¡ã
åºå®ããã«ãåè£æ°ã®å°ãªãç¹ãããã£ãã»ãããããããªæ°ãããããåè£æ°ã®è¨ç®ã«æéãããããã¡ãã£ã¨å
ã®æ¹ã«é£ããå ´æããã£ã¦ããã£ã¡æ¹æ³ã«é²ãã¨ã¯éããªããã¨ãã£ãåé¡ããã£ã¦ã¹ã³ã¢ãæªãã£ãã®ã§æçµçã«ã¯åºå®é ã§è¡ããã¨ã«ãã
Hã®é çªã決ãããã次ã¯Hã®1ç¹ç®ã«å¯¾å¿ããG(大ããæ¹ã®ã°ã©ã)ã®ç¹ã決ãã¦(å
¨é ç¹åã)ãæ¢ç´¢ãè¡ã
å
¨æ¢ç´¢ã ã¨ã¨ã¦ãæéãããã£ã¦ãã¾ãã®ã§ãã¾ãæåã«åæ¢ç´¢ãè¡ã£ã
ããé ç¹ã®ãããã³ã°ã«å¤±æããã¨ãã«ãæ®éã®å
¨æ¢ç´¢ã ã¨ã²ã¨ã¤åã®é ç¹ã¾ã§æ»ãã¨ãããããããã³ã°ã«å¤±æããåå ã¨ãªãé ç¹ã¾ã§ä¸æ°ã«å
¨é¨æ»ã
ãã¨ã§æ°ã¥ããã®ã ãããããããã¡ãã£ã¨æ¹è¯ããã¨åã§ãªããªãã®ã§å
¨æ¢ç´¢ã®æ¹è¯ãã§ãã(çµç¤ã§ä¸æ°ã«ä¼¸ã³ãã®ã¯ããã®å½±é¿ã大ãã)
ã¾ãããã¾ãè¡ãã¨ãã¯ããã¦ãããã«è§£ãè¦ã¤ãã£ã¦ããã¾ãè¡ããªãã¨ãã¯ãã¤ã¾ã§ãã£ã¦ãçµäºããªãæãã ã£ãã®ã§ããããªãå
¨æ¢ç´¢ãããã®ã§ã¯ãªãã¦æ¢ç´¢æ¨ã®åå²æ°ãæå1ã«å¶éã(ã¤ã¾ããããã¯ãã©ãã¯ããªã)ãããã§è¦ã¤ãããªããã°2ã«ããããã§ãã ããªãåæ¢ç´¢âå
¨æ¢ç´¢ãè¡ã£ã
åºå®é ã®è¨ç®
åºå®é ã®è¨ç®æ³ã¯ãã¾ãæåã«ï¼ç¹ã決ãã¦ããã§ã«æ±ºããé ç¹éåUã«æ¬¡ã®ãããªæ¹æ³ã§é ç¹ã追å ãã¦ãããã¨ã«ããè¡ã£ã
- Uã®2ç¹ä»¥ä¸ã¨æ¥ç¶ãã¦ããé ç¹ãããã°ããã®ä¸ã§Uã¨ã®æ¥ç¶æ¬¡æ°ããã£ã¨ã大ããç©ãå ãã
- ãã®ãããªé ç¹ããªããã°ãUããåºçºãã¦Uã«æ»ã£ã¦ããæå°ç¡åéè·¯ãæ¢ãããã®éè·¯ä¸ã®ç¹ãé çªã«è¿½å ãã
- ãã®ãããªéè·¯ããªããã°ãUããåºçºãã¦ãã©ãã«ãé²ããªããªãæå°ã®ãã¹ããããããã®ãã¹ä¸ã®ç¹ãé çªã«è¿½å ãã
æåã®ä¸ç¹ã®è¨ç®ã¯ãå
¨ã¦ã®ç¹ã«å¯¾ãã¦ããããï¼ç¹ç®ã¨ããå ´åã«ãã®å¾ï¼åéè·¯ã辿ãã®ã«ä½é ç¹å¿
è¦ããè¨ç®ãããã£ã¨ãå°ããã®ãæ¡ç¨ãã
ãããªæãã§åºç¤ã«é£ããå ´æ(åºæ¬çã«è¾ºã®æ°ãå¤ãã»ã©é£ãã)ãæ¢ç´¢ããã°ãã§ããã ãæ©ã段éã§è§£ããªãã¨å¤å®ã§ãã¦å®è¡æéãçããªãã¯ã
æ¢ç´¢ã®æ¹æ³
f(v)=v2ãvâV(H)ã«å¯¾å¿ããç¹ãv2âV(G)ã§ãããã¨ãæå³ããã¨ãã
æ¢ç´¢ã¯f(v)ã®å¤ãv=0ããé ã«æ±ºãã¦ãããã¨ã«ããè¡ã
æåã®ç¹ã¯|V(G)|åã®å¯è½æ§ãããã®ã§å
¨éãåããã¨ã«ãã£ã¦æ±ºããã¨ãã¦ã1çªããå
ã®ç¹vã«å¯¾ãã¦ã¯æ¬¡ã®ããã«è¡ã
- vã«é£æ¥ããç¹u(<v)ãæ¢ãã¦ãã
- f(u)ã«é£æ¥ããç¹v2ãæ¢ãã¦ãã
- f(v)=v2ã¨ããã¨ãã«ãv2ã®é£æ¥é¢ä¿ã大ä¸å¤«ããã§ãã¯ãã
- 大ä¸å¤«ãªãf(v)=v2ã¨ãã¦v+1ã®ãããã³ã°ãè¡ã
- v+1ã®ãããã³ã°ã«å¤±æãããv2ã®ä»ã®åè£ã調ã¹ã
ããèããã¨ãv+1ã®ãããã³ã°ã«å¤±æããåå ãf(v)=v2ã¨ã¯ç¡é¢ä¿ã§ãã£ãå ´åãv2ãä»ã®ç¹ã«å¤ãã¦ããã¯ã失æãããã¨ã確å®ãã¦ããã®ã§ããã«åã®é ç¹ã¾ã§ä¸æ°ã«ãã©ããã¨ãã§ãã
ããã§ããããã³ã°ã«å¤±æããåå ã¨ãªãé ç¹ã®ãªã¹ãretãç¨æãã次ã®ããã«æ¹è¯ãã
- vã®ãããã³ã°ã«ããã失æã®åå ãªã¹ãret_vãå¥ã«ç¨æãã
- vã«é£æ¥ããç¹u(<v)ãæ¢ãã¦ãã¦ãret_vã«uã追å (f(u)ãå¤åããã°ãf(v)ã®åè£ç¹ãå¤åããã®ã§å¯è½æ§ãçãã)
- f(u)ã«é£æ¥ããç¹v2ãæ¢ãã¦ãã¦ãf(v)=v2ã¨ããã¨ããv2ã®é£æ¥é¢ä¿ã大ä¸å¤«ããã§ãã¯ãé§ç®ã ã£ãå ´åã«ã¯ãã®åå ã®ãã¡ã§æãçªå·ã®å°ãããã®ãret_vã«è¿½å ãã(ä¸çªå°ããã®ä»¥å¤ãå¤åãã¦ããçµå±ä¸çªå°ãããã¤ã®ããã§f(v)=v2ã®ãããã³ã°ã¯å¤±æãã)
- 大ä¸å¤«ãªãf(v)=v2ã¨ãã¦v+1ã®ãããã³ã°ãè¡ã(ãã®æç¹ã§retã¨ret_vã¯å¥ç©ã®ã¾ã¾)
- v+1ã®ãããã³ã°ã«å¤±æããã¨ããretã«vãå«ã¾ãã¦ãããã調ã¹ãå«ã¾ãã¦ããªããã°ä»ã®åè£ã調ã¹ãå¿ è¦ã¯ãªãããã®ã¾ã¾ãªã¿ã¼ã³(retããã®ã¾ã¾)
- å«ã¾ãã¦ããå ´åã¯ãv2ãå¤åãããã°ãã¾ãè¡ããããããªãã®ã§ä»ã®åè£ã調ã¹ã
- å ¨ã¦ã®åè£ã§é§ç®ã ã£ãå ´åã¯ãret_vã®è¦ç´ ãå ¨é¨retã«å ãã¦ãªã¿ã¼ã³
ãã®æ¹è¯ã«ãããã¼ã«ã«ã§ã¯1000ç¹ä»¥ä¸ä¸ãã£ã(TCé¯ä¸ã§ã¯500ç¹ãããããä¸ãããªãã£ã)
é«éå
ç°¡åãªã±ã¼ã¹ã§ã¯ãã»ã¨ãã©è©°ã¾ããã¨ãªãåã«æéã¨ã®åè² ã ã£ãã®ã§ãé«éåãå¿
è¦ã ã£ã
Javaã§ãé«éåãçµæ§ããã°ã£ã¦ãããããã¯ãC++ã«ããã»ããè¯ãã®ã¯æãã
ã§ããC++ã«ç§»è¡ããã¨ã¢ã«ã´ãªãºã çãªæ¹è¯ãåºæ¥ãªãèªä¿¡ããã£ãã®ã§ãçµç¤ã®ãªã®ãªã¾ã§Javaã§ãã£ã¦ããC++ã«ç§»è¡ãã¦ã²ãããé«éåç¥ãããã
çµå±C++移è¡ã«ãããã¼ã«ã«ã§ã¯800ç¹ãããä¸ãã£ã(TCé¯ä¸ã§ã¯400ç¹ããã)
åçç¹
ãã¼ã«ã«ãã¹ã¿ã¼ã¨ãã¸ã¥ã¢ã©ã¤ã¶ã®ä»æ§ä¸ãã¤ã³ã¿ã©ã¯ãã£ãã«ããã®ãããã©ãã£ãã®ã§ãã©ãã300ç¹ãããã¾ã§ããåããªãã ããã¨æã£ã¦å
¥åã¯300ç¹åããããããã¡ã¤ã«ã«åãã¦ããããªãã¤ã¬ã¯ãã§èµ·åããã¨ãããã¨ãè¡ã£ã¦ããããçµç¤ã«ãªã£ã¦300ç¹ãªãã¦è»½ã¼ãè¶
ããã¨ããç¶æ³ã«ãªã£ã¦ãã¾ã£ã
å®ã¯ããã¤ãã®ä¸ã«ã¯1000ç¹è¿ãåãã¦ãã®ãããã¿ããã§ããããªãã¨ããããæ¢ç´¢ã ãã§ãªãåºå®é ã®è¨ç®ã¨ããããã«ããã¯ã«ãªã£ã¦ããã¨æãããããã辺ãã¡ããã¨æé©åãã¹ãã ã£ãorz
ãã¨ãã»ã¼å
¨é¨è§£ããã®ãªããGã«å«ã¾ããã¯ãªã¼ã¯ã®ä½ç½®ãããããã調ã¹ã¦ããã£ã¦ããã®ãæå¹ã ã£ããããããªã
Gã«ã¯ãªã¼ã¯ãå°ããããªã(å¤ãã®ã±ã¼ã¹ã§3ã¯ãªã¼ã¯ã¯å¤§éã«å«ã¾ãã¦ããããç°¡åãªã±ã¼ã¹ã ã¨4ã¯ãªã¼ã¯ãä¸æ¡åã¨ãããã¨ããã)å ´åã«ä¸æ°ã«åè£ãçµããã®ã ããGã«å°ããããªãã¨ãããã¨ã¯Hã«å«ã¾ãã¦ããå¯è½æ§ãå°ããããªãã¦å½¹ã«ç«ããªãã ããã¨æã£ã¦ãã
ããããç°¡åãªåé¡ã§ã¯ããªã大ããã°ã©ãã¾ã§è§£ãããã¨ãèããã¨ãHã«ãçµæ§å«ã¾ãã¦ãããã ã£ã
ãã¾ã
ãããã°ãªã©ã®ç®çã§ã°ã©ããã¸ã¥ã¢ã©ã¤ã¶ãä½æãã
大éã®é ç¹ãå¹³é¢ã«æç»ããã¨è¾ºãéãªã£ã¦ã¯ã±ãåãããªããªãã®ã§ãä¸æ¬¡å
ã§é
ç½®ãã¦ãããããåããããã«ãã
é ç¹æ°ãå¤ããªã£ã¦ãå
¨ä½ã®æ§é ãç´°ããé¨åã®æ¥ç¶é¢ä¿ãã¡ããã¨ããã£ã¦ããæã
ãã£ãããªã®ã§å
Ž
http://ow.ly/2ll3X
ã±ããã¼ã©ã¯ã¦ãã¨
使ãæ¹
ããã«ã¯ãªãã¯ã§èµ·å
å§ç¹ çµç¹ (辺ã®ã©ãã«)
ãä¸è¡ã«1辺ãã¤å
¥å
ã¾ã¨ããªé
ç½®ã«ãªãã¾ã§Showãã¿ã³ãé£æ
ãã©ãã°ã§å転
é ç¹ãå³ã¯ãªãã¯ã§ãã®ç¹ã«æ¥ç¶ãã辺ã®ã¿ã表示