ã‚ュゥã¹ãˆã¯ãƒ¯ãƒ«ãƒ—ルギスã®å¤œã«å‘ã‘ã¦é”女ã®åˆæˆã«æ˜Žã‘暮れã¦ã„る.ワルプルギスã®å¤œã®ãŸã‚ã«ï¼Œç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ (é”女ã®åµ) を使ã£ã¦æ‰‹ã«å…¥ã‚Œã‚„ã™ã„é”女をã†ã¾ãåˆæˆã—目的ã§ã‚る舞å°è£…ç½®ã®é”女を創り上ã’ãªã‘ã‚Œã°ãªã‚‰ãªã„ã‹ã‚‰ã§ã‚る.
ã‚ュゥã¹ãˆã¯æ‰‹ã«å…¥ã‚Œã‚„ã™ã„種類ã®é”女ã®ã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã‹ã‚‰é”女ã®ç´ ã¨ãªã‚‹ã‚‚ã®ã‚’å–り出ã—,空ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã«å…¥ã‚Œã‚‹ã“ã¨ã§ï¼Œãã®ã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã«é”女を宿らã›ã‚‹ã“ã¨ãŒã§ãる.ã¾ãŸï¼Œã“ã®ä¸–ç•Œã«ã¯ï¼Œã‚る組ã¿åˆã‚ã›ã§è¤‡æ•°ã®é”女をåˆæˆã™ã‚‹ã¨æ–°ãŸãª 1 ã¤ã®é”女を生ã¿å‡ºã™ã“ã¨ãŒã§ãã‚‹ã¨ã„ã†åˆæˆæ³•å‰‡ãŒã„ãã¤ã‹ã‚る.ãã“ã§ï¼Œã„ãã¤ã‹ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã‚’使ã„,ãれらã®ä¸ã«ã‚ã‚‹é”女ã®ç´ ã¨ãªã‚‹ã‚‚ã®ã‚’åˆæˆã—,1 ã¤ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã«æ–°ãŸãªé”女を宿らã›ã‚‹ã“ã¨ãŒã§ãる.ã¾ãŸï¼Œåˆæˆã—ãŸçµæžœç©ºã¨ãªã£ãŸç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã¯å†åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる.例ãˆã°ï¼Œ3 個ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã«å…¥ã£ãŸé”女をåˆæˆã™ã‚‹ã¨ï¼Œãれら㮠3 個ã®ã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã¯ï¼Œæ–°ãŸãªé”女ãŒå®¿ã£ãŸ 1 個ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã¨ 2 個ã®ç©ºã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã¨ãªã‚‹ï¼Žã—ã‹ã—,åŒã˜ç¨®é¡žã®é”女をåŒæ™‚ã«è¤‡æ•°ã®ã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã«å…¥ã‚Œã‚‹ã“ã¨ã¯å‡ºæ¥ãªã„.
ã‚ュゥã¹ãˆã¯é”女ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã¸ã®å¯„宿ã¨é”女ã®åˆæˆã‚’ç¹°ã‚Šè¿”ã™ã“ã¨ã«ã‚ˆã‚Šèˆžå°è£…ç½®ã®é”女を創りã ã—ãŸã„.舞å°è£…ç½®ã®é”女を創りã ã™ã«ã¯ã„ãã¤ã®ç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ãŒå¿…è¦ã‹æ±‚ã‚よ.
入力ã¯ä»¥ä¸‹ã®ã‚ˆã†ãªå½¢å¼ã§ä¸Žãˆã‚‰ã‚Œã‚‹ï¼Ž
N\ E\ T\\ W_1\ W_2\ …\ W_N\\ G_1\ C_1\ S_{1,1}\ S_{1,2}\ …\ S_{1,C_1}\\ G_2\ C_2\ S_{2,1}\ S_{2,2}\ …\ S_{2,C_2}\\ …\\ G_E\ C_E\ S_{E,1}\ S_{E,2}\ …\ S_{E,C_E}\\
N ã¯é”女ã®ç¨®é¡žã®å€‹æ•°ï¼ŒE ã¯åˆæˆæ³•å‰‡ã®å€‹æ•°ï¼ŒT ã¯èˆžå°è£…ç½®ã®é”女ã®ç•ªå·ã§ã‚る.W_i 㯠i 番目ã®é”女ãŒæ‰‹ã«å…¥ã‚Œã‚„ã™ã„é”女ã§ã‚ã‚‹ã‹ã©ã†ã‹ã‚’表ã—,1
ãªã‚‰ã°æ‰‹ã«å…¥ã‚Œã‚„ã™ã„é”女ã§ã‚り,0
ãªã‚‰ã°æ‰‹ã«å…¥ã‚Œã‚„ã™ã„é”女ã§ã¯ãªã„.
続ã E è¡Œã«åˆæˆæ³•å‰‡ãŒæ¬¡ã®ã‚ˆã†ã«è¡¨ã•ã‚Œã‚‹ï¼šã€Œç•ªå·ãŒ S_{i,1}\ S_{i,2}\ …\ S_{i,C_i} ã®é”女をåˆæˆã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ G_i ã®ç•ªå·ã®é”女ãŒå¾—られる.ã€
舞å°è£…ç½®ã®é”女を創りã ã™ã®ã«æœ€ä½Žé™å¿…è¦ãªç‰¹åˆ¥ãªã‚°ãƒªãƒ¼ãƒ•ã‚·ãƒ¼ãƒ‰ã®å€‹æ•°ã‚’出力ã›ã‚ˆï¼Žå‰µã‚Šã ã™ã“ã¨ãŒã§ããªã„å ´åˆã¯ -1
を出力ã›ã‚ˆï¼Ž
3 1 3 1 1 0 3 2 1 2
2
5 0 1 1 1 1 1 1
1
18 5 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 2 3 4 5 2 2 6 7 3 3 8 9 10 4 4 11 12 13 14 5 4 15 16 17 18
5
6 4 6 1 1 1 0 0 0 4 2 1 2 5 2 2 3 6 2 4 5 6 3 1 2 4
3
13 9 13 1 1 0 1 1 0 1 1 0 1 1 0 0 3 2 1 2 6 2 4 5 9 2 7 8 12 2 10 11 6 2 2 3 9 2 5 6 12 2 8 9 3 2 11 12 13 4 3 6 9 12
5
4 4 4 1 1 0 0 1 2 2 3 2 2 3 1 3 2 1 2 3 3 1 2 4
-1