codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

246D.md (2251B)


      1 Source: https://codeforces.com/problemset/problem/246/D
      2 
      3 D. Colorful Graph
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*.
     22 
     23 Let's consider all vertices of the graph, that are painted some color *k*. Let's denote a set of such as *V*(*k*). Let's denote the value of the neighbouring color diversity for color *k* as the cardinality of the set *Q*(*k*) = {*c**u* :  *c**u* ≠ *k* and there is vertex *v* belonging to set *V*(*k*) such that nodes *v* and *u* are connected by an edge of the graph}.
     24 
     25 Your task is to find such color *k*, which makes the cardinality of set *Q*(*k*) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color *k*, that the graph has at least one vertex with such color.
     26 
     27 Input
     28 
     29 The first line contains two space-separated integers *n*, *m* (1 ≤ *n*, *m* ≤ 105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers *c*1, *c*2, ..., *c**n* (1 ≤ *c**i* ≤ 105) — the colors of the graph vertices. The numbers on the line are separated by spaces.
     30 
     31 Next *m* lines contain the description of the edges: the *i*-th line contains two space-separated integers *a**i*, *b**i* (1 ≤ *a**i*, *b**i* ≤ *n*; *a**i* ≠ *b**i*) — the numbers of the vertices, connected by the *i*-th edge.
     32 
     33 It is guaranteed that the given graph has no self-loops or multiple edges.
     34 
     35 Output
     36 
     37 Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 6 6  
     45 1 1 2 3 5 8  
     46 1 2  
     47 3 2  
     48 1 4  
     49 4 3  
     50 4 5  
     51 4 6
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 3
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 5 6  
     64 4 2 5 2 4  
     65 1 2  
     66 2 3  
     67 3 1  
     68 5 3  
     69 5 4  
     70 3 4
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 2
     77 ```