Small World Network
InterviewTime limit1sMemory limit512 MB
Given a graph of N people and K friendships, check whether every pair of people is connected within 6 steps, printing Small World! or Big World! accordingly.
- Level
Medium4 of 10
- Topics
- Graph, BFS, Shortest path, Implementation
- Solved
- No attempts yet
Problem
The small world network is a theory first described by Professor Milgram in 1967.
Put simply, it says that even if an entire network is huge, everyone in it can still be closely connected.
In this theory, Professor Milgram argued that all people on Earth can be connected in at most 6 steps.
For example, even if the person who made this problem, Mr. Kim (23), and Lee Ji-eun (27) have never met, they are connected through at most 6 steps.

In the figure above, the vertices are people and the edges are friendships. Every pair of vertices in the left graph is connected in 6 steps or fewer, so it satisfies the small world network. In the right graph, however, the green vertices require 7 steps to connect, so it does not satisfy the small world network.
Mr. Kim became doubtful about this theory and wanted to check whether all people on Earth really can be connected in at most 6 steps.
For Mr. Kim, write a program that, given the friendships of all people on Earth, checks whether the small world network actually holds.
Input
The first line gives the number of people on Earth N and the number of friendships K. Every person is numbered from 1 to N. (1 ≤ N ≤ 100, 0 ≤ K ≤ N×(N-1)/2)
From the second line to the (K+1)-th line, each line gives A B, representing a friendship. (1 ≤ A, B ≤ N)
If A and B are friends, then B and A are friends. No one is friends with themselves. The same friendship A and B is not given more than once.
Output
If the network satisfies the small world network, print "Small World!"; otherwise, print "Big World!".