CodeforcesR1500以ä¸
åç½®ãã«ç´¯ç©åãã¨ãã®ã3 ã¶æåã®åã ã£ããæãã¤ããªãã£ããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ãããããã¾ããé·ã ã® 0 㨠1 ã®ã¿ãããªãæåå ãä¸ãããããæåå ã«å¯¾ãã¦ä»¥ä¸ã®æä½ãè¡ããã¨ãã§ããã æåå ä¸ã®æå "0" â¦
é¢ç½ãã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã ã®ç´æ°ã§ãã£ã¦ã ã®åæ°ã§ã¯ãªããããªæ´æ°ã®æ大å¤ãæ±ããã (ã¨ãããã¼ã¿ã»ããã åä¸ãããã) å¶ç´ èããã㨠ã®ç´æ°ããã¹ã¦åæããã®ã§ã¯éã«åããªããã¨ãããã èªèº«ã ã§å²ãåâ¦
ã¾ã 1 ã¤ãã«ãã³åã«é¢ããåé¡ãèªçãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®ã«ãã³åãä¸ãããããã«ãã³åã«ä»¥ä¸ã®æä½ã好ããªé åºã§å¥½ããªåæ°ã ãæ½ãã¦ãæ´åãåããç¶æ ãã«ãããã ã«ãã³åã®ããåºéã«ã¤ãã¦ãä»»æã®é åºã«ä¸¦ã³æ¿ãã ãã®ã¨ãâ¦
é¢ç½ãã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è¦ç´ ã®æ°å ãä¸ããããã以ä¸ã®æ¡ä»¶ãæºãããããªé¨åæ°åã®ãã¡ãè¦ç´ åã®æ大å¤ãæ±ããã æãåºããæ°åã®ã©ã® 2 é ã«ã¤ãã¦ããå¤ã®å·®åãã¨ãindex ã®å·®åãã¨ãçãã å¶ç´ èããã㨠ãã¨ãã° ã®å ´åã¯ããâ¦
ããããªãã§ã 2 åã§è§£ããåé¡ã¨ã¯æããªãã®ã§ãã... åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 2 à N ã®ã°ãªãããä¸ãããããæåã¯ã°ãªããã®ãã¹ã¯ãã¹ã¦ãéè·¯ãã®ç¶æ ã§ãã£ã¦ããã¹ (1, 1) ãããã¹ (2, N) ã«å°éãããã¨ãã§ããã以ä¸ã® q åã®ã¯ã¨ãªã«çãâ¦
ãã¢ãªã³ã°ç³»ã®åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã®åé¡ã ååºé¡ãããã®ã§ããããçãã: ã³ã¼ãã¼ã 人ãæ°å¦ã«å¼·ã人ã 人ããªãã§ããªã人ã 人ãã ããããã³ã¼ãã¼ 1 人以ä¸ãæ°å¦å¼·ã人ã 1 人以ä¸ãå«ã 3 人ãã¼ã ãæ大ä½çµã§ãããæ±ãã èâ¦
誤èªãã¦å¤§ããåºé ãã... åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ãããããããããããä½åãã®ã°ã«ã¼ãã«åãã¦ãåã°ã«ã¼ãã«ã¤ãã¦ãã°ã«ã¼ãå ã®ãã¹ã¦ã®æ´æ°ãã°ã«ã¼ãå ã®æå°å¤ã§å²ãåãããã¨ããæ¡ä»¶ãæºããããã«ãããã ãããå®ç¾ããããã®â¦
è¶ è¦æç³»ããªãã¨ã解ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã N ã®ãã¤ããªå a, b ãä¸ãããããa ã«å¯¾ã㦠é£æ¥äºé ã swap ãã 0 㨠1 ãå転ãã ã®æä½ãæå°åæ°è¡ã£ã¦ b ã«ããã(10 -> 01 ãªã 1ã1000 -> 0001 ãªã 2) å¶ç´ 1 <= N ,= 106 èãããâ¦
# åé¡æ¦è¦ ç¡åã°ã©ã (é ç¹æ° n, ææ° m) ãä¸ããããã ãã®ã°ã©ãã®é ç¹éåãäºãã« disjoint 㪠2 ã¤ã®éå A, B ã«åå²ãã¦ã A, B ãã¨ãã« vertex cover ã¨ãªã£ã¦ããããã«ããã ãã®ãããªãã®ãåå¨ããªããã° -1 ããªã¿ã¼ã³ããã # å¶ç´ 2 â¤â¦