Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://codeforces.com/contest/1829/problem/F
- The snowflake graph is generated from two integers x And y, which are more 1 , in the following way:
- Start at one central vertex. Connect x new vertices to this central vertex. Connect ynew vertices to each of these x peaks.
- For example, below is a snowflake graph for x = 5 And y= 3.
- 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.
- For a given snowflake graph, determine the values x And y.
- Input data
- The first line contains one integer t(1 ≤ t ≤ 1000) is the number of input data sets in the test.
- The first line of each test case contains two integers n And m
- (2 ≤ n ≤ 200 ;1 ≤ m ≤ min ( 1000 ,n ( n − 1 )2)) is the number of vertices and edges in the graph, respectively.
- Next m lines contain two integers u And v
- (1 ≤ u , v ≤ n ,u ≠ v) are the numbers of vertices connected by an edge. The graph does not contain multiple edges and loops.
- It is guaranteed that this graph is a snowflake graph for some integers x And y, which are more 1.
- Output
- For each test case, on a separate line print the values x And y, in that order, separated by a space.
- Example
- input data
- 3
- 21 20
- 21 20
- 5 20
- 13 20
- 13
- 11 3
- 10 3
- 4 8
- 19 8
- 14 8
- 9 7
- 12 7
- 17 7
- 18 6
- 16 6
- 26
- 6 15
- 7 15
- 8 15
- 20 15
- 3 15
- 7 6
- 12
- 13
- 24
- 25
- 3 6
- 3 7
- 9 8
- 9 3
- 3 6
- 6 2
- 2 1
- 5 2
- 27
- 4 3
- 3 8
- output
- 5 3
- 2 2
- 2 3
- Note
- 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
- ---------------------------------------------------------------------------------------------------------------------------------
- #include<bits/stdc++.h>
- using namespace std;
- void solve(){
- int n,m;
- cin>>n>>m;
- vector<int> adj[n+1];
- unordered_map<int,int> deg;
- for(int i=0;i<m;i++){
- int u,v;
- cin>>u>>v;
- adj[v].push_back(u);
- adj[u].push_back(v);
- deg[u]++;
- deg[v]++;
- }
- unordered_set<int> xLayer;
- for(auto m: deg){
- if(m.second==1){
- int nei=adj[m.first][0];
- xLayer.insert(nei);
- }
- }
- cout<<xLayer.size()<<" "<<adj[*xLayer.begin()].size()-1<<endl;
- }
- int main(){
- int TC;
- cin>>TC;
- while(TC--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment