Question
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String input_cancel_from = bufferedReader.readLine();
String input_cancel_to = bufferedReader.readLine();
int input_g_num_nodes = Integer.parseInt(bufferedReader.readLine().trim());
List input_g_nodes_data = IntStream.range(0, input_g_num_nodes).mapToObj(i -> { try { return bufferedReader.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } }) .collect(toList());
String[] input_gNodesEdges = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
int input_gNodes = Integer.parseInt(input_gNodesEdges[0]); int input_gEdges = Integer.parseInt(input_gNodesEdges[1]);
List input_gFrom = new ArrayList(); List input_gTo = new ArrayList();
IntStream.range(0, input_gEdges).forEach(i -> { try { String[] input_gFromTo = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
input_gFrom.add(Integer.parseInt(input_gFromTo[0])); input_gTo.add(Integer.parseInt(input_gFromTo[1])); } catch (IOException ex) { throw new RuntimeException(ex); } });
bufferedReader.close(); } }
================== The final solutions ===========
Sample Input 0
San Francisco Los Angeles 8 San Diego Los Angeles San Francisco San Jose Sacramento Santa Barbara Las Vegas Pheonix 8 17 0 1 0 3 1 0 1 2 1 4 1 3 2 1 2 5 2 6 2 7 3 7 3 0 3 1 5 2 6 2 7 2 7 3
Sample Output 0
True
Sample Input 1
San Francisco Las Vegas 8 San Diego Los Angeles San Francisco San Jose Sacramento Santa Barbara Las Vegas Pheonix 8 19 0 1 0 3 1 0 1 2 1 4 1 3 2 1 2 5 2 6 2 7 3 7 3 0 3 1 4 7 4 1 5 2 6 2 7 2 7 3
Sample Output 1
False
Sample Input 2
Dubai Helsinki 10 Dubai Helsinki Oslo Bergen Copenhagen Berlin Stockholm Cairo Tangier Oman 10 29 0 7 0 1 0 9 1 0 1 2 1 4 1 5 1 6 2 1 2 4 2 6 2 5 2 3 3 2 4 5 4 1 4 6 4 2 5 4 5 1 5 2 6 1 6 2 6 4 7 9 7 8 8 7 9 0 9 7
Sample Output 2
FalseAirlines haven't been doing so well recently. In addition to make the seats miniscule, getting rid of the individual TVs, no longer serving peanuts, killing pets, and not seating people for wearing clothes they don't like, they're also cancelling flights. They want to cancel all flights between cities A and B where the fewest passengers travel directly from A to B. However they don't want to remove flights that would mean two cities are no longer connected by air travel (they don't care if this suddenly means you now have to take 4 flights instead of 1) Given origin and destination cities, your job is to figure out if cancelling all flights between those two cities will disconnect two previously connected cities Input . The first two lines contain the cities the airline wishes to cancel flights between The remaining input describes a graph where each edge is a flight between two cities - The next line contains an integer n, the number of cities the airline serves - The next n lines each contain a city served by the airline. This makes up an array of verticies -The next line contains two space-separated integers: n e - The next e lines each contain two space-separated integers a and b that describes an edge from the vertex indexed at a to the vertex indexed at b Constraints You can assume the flight graph is originally connected and is undirected-i.., if there are flights from AiB there are flights from BiA and a single edge represents both. Output A single line containing "True" or "False" indicating whether they can remove the flights See the hackerrank problem for sample input and output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started