RainX_69

Codeforces DIV 4F. Must do | Maths | OA

May 8th, 2023
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | Source Code | 0 0
  1. https://codeforces.com/contest/1829/problem/F
  2.  
  3. The snowflake graph is generated from two integers x And y, which are more 1 , in the following way:
  4. Start at one central vertex. Connect x new vertices to this central vertex. Connect ynew vertices to each of these x peaks.
  5. For example, below is a snowflake graph for x = 5 And y= 3.
  6. The snowflake graph above has a central vertex 15 , then x = 5 vertices connected to it (3,6,7,8 And 20), and then y= 3 vertices connected to each of them.
  7. For a given snowflake graph, determine the values x And y.
  8.  
  9. Input data
  10. The first line contains one integer t(1 ≤ t ≤ 1000) is the number of input data sets in the test.
  11. The first line of each test case contains two integers n And m
  12. (2 ≤ n ≤ 200 ;1 ≤ m ≤ min ( 1000 ,n ( n − 1 )2)) is the number of vertices and edges in the graph, respectively.
  13. Next m lines contain two integers u And v
  14. (1 ≤ u , v ≤ n ,u ≠ v) are the numbers of vertices connected by an edge. The graph does not contain multiple edges and loops.
  15. It is guaranteed that this graph is a snowflake graph for some integers x And y, which are more 1.
  16.  
  17. Output
  18. For each test case, on a separate line print the values x And y, in that order, separated by a space.
  19.  
  20. Example
  21.  
  22. input data
  23. 3
  24. 21 20
  25. 21 20
  26. 5 20
  27. 13 20
  28. 13
  29. 11 3
  30. 10 3
  31. 4 8
  32. 19 8
  33. 14 8
  34. 9 7
  35. 12 7
  36. 17 7
  37. 18 6
  38. 16 6
  39. 26
  40. 6 15
  41. 7 15
  42. 8 15
  43. 20 15
  44. 3 15
  45. 7 6
  46. 12
  47. 13
  48. 24
  49. 25
  50. 3 6
  51. 3 7
  52. 9 8
  53. 9 3
  54. 3 6
  55. 6 2
  56. 2 1
  57. 5 2
  58. 27
  59. 4 3
  60. 3 8
  61.  
  62. output
  63. 5 3
  64. 2 2
  65. 2 3
  66. Note
  67. The first test case is shown in the condition. Note that the output 3 5 is incorrect , since it must first be output x, and then y
  68. ---------------------------------------------------------------------------------------------------------------------------------
  69.  
  70. #include<bits/stdc++.h>
  71. using namespace std;
  72.  
  73. void solve(){
  74.     int n,m;
  75.     cin>>n>>m;
  76.     vector<int> adj[n+1];
  77.     unordered_map<int,int> deg;
  78.     for(int i=0;i<m;i++){
  79.         int u,v;
  80.         cin>>u>>v;
  81.         adj[v].push_back(u);
  82.         adj[u].push_back(v);
  83.         deg[u]++;
  84.         deg[v]++;
  85.     }
  86.     unordered_set<int> xLayer;
  87.     for(auto m: deg){
  88.         if(m.second==1){
  89.             int nei=adj[m.first][0];
  90.             xLayer.insert(nei);
  91.         }
  92.     }
  93.     cout<<xLayer.size()<<" "<<adj[*xLayer.begin()].size()-1<<endl;
  94. }
  95.  
  96. int main(){
  97.     int TC;
  98.     cin>>TC;
  99.     while(TC--){
  100.         solve();
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment