## Inaho

View as PDF

Points: 20 (partial)
Time limit: 3.0s
Memory limit: 512M

Author:
Problem types
Allowed languages
C, C++

Inaho Kaizuka has a bionic eye. It has a lot of software on it, including some "games". One game Inaho is particularly fond of is "Graph Simulator 2015". In this game, Inaho controls a graph with vertices and initially no edges. He may choose to arbitrarily add a bidirectional edge between two vertices, remove the most recent edge added in the graph, or query the size of the connected component of a vertex. Unfortunately, the game Inaho currently has is broken — you need to write an exact copy of it.

#### Implementation Details

You should write a program which implements the bionic eye's software "Graph Simulator 2015". Locally, your program should include the header file inaho.h by #include "inaho.h". When grading your submission online, the judge will automatically prepend this line to your file.

Your program should implement the following procedures.

• void Init(int N) This procedure is called only once in the beginning. The parameter is the number of vertices Inaho is simulating. Use it to perform any initialization your program might need.
• void AddEdge(int U, int V) This procedure is called when Inaho adds an edge between two vertices and in his graph. It will hold that .
• void RemoveLastEdge() This procedure is called when Inaho removes the most recent edge added to the graph by AddEdge that has not already been removed. It is guaranteed that there is at least one edge in the graph when this procedure is called.
• int GetSize(int U) This procedure is called when Inaho queries for the size of the connected component of a vertex. You should return that size as an int. It will hold that .

You can find a sample grader in the C language here.

You can find the header inaho.h here.

You can find sample input for the sample grader with Windows-style line endings here.

#### Constraints

All input data satisfy the following conditions.

• .
• The total number of calls to AddEdge, RemoveLastEdge, and GetSize is less than or equal to .

#### Note

The grader will generate correct input and output dynamically. This means that the time and memory on the submission results page may not necessarily be solely from your program's execution. The time and memory limits have been adjusted to allow for up to 1 second and 256MB for the generator to generate input and output. The generator will free its memory after generation.

• Ninjaclasher  commented on Sept. 15, 2017, 1:07 p.m. edit 2

Can an edge be added between U and V twice?

• Ninjaclasher  commented on May 30, 2017, 8:23 p.m.

I don't really understand what it means by "size of the connected component of a vertex." Does it mean how many AddEdges have been called to add an edge U and V? Thanks in advance.

• wleung_bvg  commented on May 30, 2017, 9:11 p.m.

The number of vertices that is in the same connected component as vertex U (including vertex U)

• d  commented on Aug. 18, 2015, 9:40 a.m.

Is the problem broken?

• FatalEagle  commented on Aug. 18, 2015, 9:01 p.m.

Fixed. All RTE submissions have been rejudged.

• kobortor  commented on Aug. 18, 2015, 4:21 p.m.

Yeah it seems, I took my (previously) AC solution and now it gets all RTE.

• FatalEagle  commented on March 18, 2015, 3:59 p.m.

To those who may not have known, although the sample grader is a C file, you can change the extension to .cpp and compile as C++.

• bobhob314  commented on May 22, 2015, 8:08 p.m. edited

Hey Tim, could you clarify how to test my solution? (As in, how to use the grader.)

• kobortor  commented on May 22, 2015, 10:05 p.m.

Run the grader and make sure to read from a file. If it successfully runs the it should tell you whether it's correct or not at the end.

• fifiman  commented on March 16, 2015, 7:23 p.m.

Can RemoveLastEdge be called twice without an AddEdge in between?

• FatalEagle  commented on March 16, 2015, 7:28 p.m.

The statement has been updated. RemoveLastEdge will remove the most recent unremoved edge.

• fifiman  commented on March 16, 2015, 7:32 p.m.

So RemoveLastEdge can be called twice in a row?

• FatalEagle  commented on March 16, 2015, 7:34 p.m.

Yes.