Created
          April 3, 2014 21:25 
        
      - 
      
- 
        Save xyos/9963230 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | t = int(raw_input()) | |
| def find_set(a,graph): | |
| s = set([a]) | |
| for st in graph: | |
| if a in st: | |
| s = st | |
| return s | |
| def add_to_graph(a,b,graph): | |
| s_a = find_set(a,graph) | |
| s_b = find_set(b,graph) | |
| s_a_b = s_a | s_b | |
| if s_a in graph: | |
| graph.remove(s_a) | |
| if s_b in graph: | |
| graph.remove(s_b) | |
| graph.append(s_a_b) | |
| print len(s_a_b) | |
| while t: | |
| t -= 1 | |
| graph = [] | |
| nodes = int(raw_input()) | |
| for i in range(nodes): | |
| a,b = raw_input().split() | |
| add_to_graph(a,b,graph) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment