Handle Requests

0

0 votes
Hard, Algorithms, Approved
Problem

For a given undirected connected weighted graph G and K servers, which can travel between two vertices u and v of G in time distance(u,v), the goal is to handle Q queries. The i-th query contains a single vertex v and demands at least one server to arrive at vertex v in order to handle the request there. So if there is no server at vertex v currently, at least one server has to be moved there with cost distance(u,v), where u is its current position. The goal is to minimize the total time needed to handle all the requests.

Input format:

In the first line there are 4 space separated integers N,M,K and Q denoting respectively the number of vertices in the graph, the number of edges in the graph, the number of servers, and the number of queries to handle. After that, M lines follow. Each of them consists of 3 space separated integers u,v,w denoting that there is an edge between vertices u and v with weight w. It the next line there are K space separated integers p1,p2,,pK, where pi denotes the initial vertex position of server i. Then, Q lines follow. On the i-th line there is a single integer qi denoting the vertex where the i-th request has to be handled.

Output format:

In the first line output a single integer A denoting the number of actions your solution performs. A must not be greater than 2107.

After that print exactly A lines. Each of these lines should be in one of two formats:

  • MOVE si vi := denoting that a server si is moved to vertex vi
  • HANDLE := denotes that the first not yet handled request is handled now

The output is considered correct if it is in the correct format, there are exactly Q HANDLE actions, and whenever a HANDLE action is performed, there is at least one server on the vertex corresponding to the query this action handles.

Constraints:

1N103
1M104
1K100
1Q105
0A2107
1u,vN
1piN
1qiN
1siK
1viN

Scoring:

For a single test case let the total time (i.e. total distance traveled by all servers) needed to handle all requests by performing all moves given in output returned by your program be time.

Now the score for the given case is defined as

(1011time)(M/N)2K

If the output for a particular case is wrong the score for that case is 0. The total absolute score of a problem is the sum of scores for all the test cases. In this problem, scoring is set to relative, which means that the final score for a problem is your absolute score divided by the score of the best solution submitted by any participant.

The objective is to minimize the time taken i.e. to maximize the score.

Test generation:

In all test cases N=103, Q=105, edge weights are generated uniformly at random from range [1,103], initial position of each server is generated uniformly at random from range [1,N], vertices corresponding to queries are generated uniformly at random from range [1,N].

There are 3 types of graphs used in the test cases, each of them is used in 1/3 test cases:

  1. path graph with N nodes
  2. random graph with N nodes and 10N edges, generated with this function
  3. random tree with N nodes generated by first picking a random graph generated in method 2, then assigning random weights to its edges, computing minimum spanning tree of this graph and returning this minimum spanning tree with edge weights removed

In each of the 3 above groups, there are 3 classes of tests denoted by the range from K is chosen uniformly at random. Each such class corresponds to 1/3 test cases in a group. These ranges are:

  1. [2,5]
  2. [10,20]
  3. [50,100]
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the sample input, the graph is a path consisting of 3 vertices, where each edge has a weight of 1. There are two servers. The first one is initially placed in vertex 1 and the second in vertex 3. There are 4 requests to handle. First request has to be handled in the vertex 2, second in vertex 1, third in vertex 2, and the last one again in vertex 1.

In the sample output, there are 8 actions performed and only the first server is ever moved to handle all requests. Each time a request in vertex v has to be handled, it is moved from its current position to v with the cost equal to the distance between these two nodes and then the request is handled. Since all edge weights are 1 and the server goes through 3 edges overall, the total cost of handling requests that way is equal to 3.

Editor Image

?