ࡱ > Oh +'0 d , 8 D L T \ IOI OI ALVES f LVE Normal ioi98 8 i9 Microsoft Word 8.0 @ L @ q۽@ X@ \Xr۽ i 0 Program Files 0 Microsoft Office 0 Templates G ՜. +,D ՜. +,0 h p | IST IOI Title 6 > _PID_GUID A N { 6 B 2 D B B C 1 - 2 C 5 4 - 1 1 D 2 - 9 A 8 7 - 0 0 0 0 2 1 8 3 2 5 0 8 } Microsoft Office 0 Templates G Polygon Polygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled with an integer and each edge is labelled with either the symbol + (addition) or the symbol * (product). The edges are numbered from 1 to N. EMBED Word.Picture.8 Figure 1. Graphical representation of a polygon On the first move, one of the edges is removed. Subsequent moves involve the following steps: pick an edge E and the two vertices V1 and V2 that are linked by E; and replace them by a new vertex, labelled with the result of performing the operation indicated in E on the labels of V1 and V2. The game ends when there are no more edges, and its score is the label of the single vertex remaining. Sample game: Consider the polygon of Figure 1. The player started by removing edge 3. The effects are depicted in Figure 2. EMBED Word.Picture.8 Figure 2. Removing edge 3 After that, the player picked edge 1, EMBED Word.Picture.8 Figure 3. Picking edge 1 then edge 4, EMBED Word.Picture.8 Figure 4. Picking edge 4 and, finally, edge 2. The score is 0. EMBED Word.Picture.8 Figure 5. Picking edge 2 Task Write a program that, given a polygon, computes the highest possible score and lists all the edges that, if removed on the first move, can lead to a game with that score. Input Data File POLYGON.IN describes a polygon with N vertices. It contains two lines. On the first line is the number N. The second line contains the labels of edges 1, ..., N, interleaved with the vertices' labels (first that of the vertex between edges 1 and 2, then that of the vertex between edges 2 and 3, and so on, until that of the vertex between edges N and 1), all separated by one space. An edge label is either the letter t (instead of +) or the letter x (instead of *). Sample Input: 4 t -7 t 4 x 2 x 5 This is the input file for the polygon of Figure 1. Output Data On the first line of file POLYGON.OUT your program must write the highest score one can get for the input polygon. On the second line it must write the list of all edges that, if removed on the first move, can lead to a game with that score. Edges must be written in increasing order, separated by one space. Sample Output: 33 1 2 This must be the output file for the polygon of Figure 1. Constraints 3 ( N ( 50 IOI Setubal 1998 EMBED MSPhotoEd.3 EMBED MSPhotoEd.3 t u 6 8 9 j k r | v w P Q y z jQr9 UVjOr9 UVCJ 6CJ CJ EH CJ CJ jir9 UV j U5OJ QJ 55CJ M : j k y # $ > p@P !$`'0* -/2p5@8 " > p@P !$`'0* -/2p5@8 1$ ! $ ! $ ! : j k y 7 P Q w ] ^ i B C Q S d e . / ; F I M N [ \ ] ^ ` c D 7 P Q w ] ^ i " > p@P !$`'0* -/2p5@8 # $ > p@P !$`'0* -/2p5@8 ! $ 3 5 6 N O P Q d e t u w x ] ^ i ^ _ d e 0 1 > ? B C O Q R S e . / ; = CJ CJ OJ QJ CJ 6CJ 5OJ QJ OJ QJ 5CJ jSr9 UVOJ QJ CJ 5 j UjRr9 UV Ki B C Q S d e . / ; F I M $$ $ $ ! " > p@P !$`'0* -/2p5@8 = > ? @ A B E F H I [ ^ c d u v w x z { n> p> r> ? ? @ @ @ @ ,A ü 5 jK CJ Uj=r9 UV j CJ Uj:r9 UV j U5CJ OJ QJ mHmH j UmH nH 5CJ CJ j "M N [ \ ] ^ _ ` a b c y z t> ? ? @ *A ,A $ $$l h! $ $$ 7 0 &P P . A!"#$% P n 5 D\ PNG IHDR U 4 6+y gAMA pHYs od IDATx[^Uk9u3cόĩB&M[6CJ w@ !A@BB+