KingdomMap
SRM 439 · 2009-04-30 · by it4.kp
Problem Statement
Your task is to create this new map. You are given an
Notes
- int[] A comes before int[] B lexicographically if and only if A contains a smaller number at the first position where they differ.
- A cycle is a sequence of cities that contains at least 3 cities and starts and ends in the same city. Each two cities that are consecutive in the sequence must be connected by a road and all these roads must be distinct.
Constraints
- n will be between 1 and 300, inclusive.
- roads will contain between 0 and 50 elements, inclusive.
- Each element of roads will contain between 1 and 50 characters, inclusive.
- The elements of roads, when concatenated together, will contain a comma-separated list of roads. Let's call the concatenated string R.
- R will contain between 0 and n-1 roads, inclusive.
- Each road in R will be formatted "u v" (quotes for clarity), where u and v are integers between 0 and n-1, inclusive, with no extra leading zeroes, and u is less than v.
- All roads in R will be distinct.
- There will be no cycles in the corresponding graph.
5
{"0 1,1 2,2 3"}
Returns: { }
There is no need to exclude any roads.
7
{"0 1,1 2,2 3,3 4,5 6,2 5"}
Returns: {0 }
In this case, we can draw a valid map after excluding any single road. Since we need the lexicographically smallest answer, we exclude the first road in the list, which has the number 0.
20
{"8 17,9 12,4 7,2 7,2 19,3 12,6 12,1 9,5 18,0 12,6 1", "6,0 11,3 14,10 15,12 13,13 18,13 19,15 17,15 19"}
Returns: {1, 3, 5, 14 }
Note that you need to concatenate all elements of roads. When concatenating elements, don't put anything between them. In this case the town "16" in the road "6 16" was cut in half between two elements of roads.
1
{}
Returns: { }
roads can be empty.
4
{"0 1,2 3"}
Returns: { }
Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class KingdomMap with a public method vector<int> getRoadsToRemove(int n, vector<string> roads) · 41 test cases · 2 s / 256 MB per case