Codeforces Round 871 (Div. 4) 1829F - Forever Winter Solution


 

Problem Link :  https://codeforces.com/contest/1829/problem/F

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. std::vector<int> adj[500];
  5. int32_t main() {
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. int t;
  9. cin >> t;
  10. while (t--) {
  11. int n , m ;
  12. cin >> n >> m ;
  13. for ( int i = 0 ; i <= n ; i++) {
  14. adj[i].clear();
  15. }
  16. for ( int i = 1 ; i <= m ; i++) {
  17. int u , v ;
  18. cin >> u >> v ;
  19. adj[u].push_back(v) ;
  20. adj[v].push_back(u) ;
  21. }
  22. int x = 0 , y = 0 ;
  23. for ( int i = 1 ; i <= n ; i++) {
  24. set<int>index;
  25. for ( auto j : adj[i]) {
  26. index.insert(adj[j].size());
  27. }
  28. if ( index.size() == 1 ) {
  29. x = adj[i].size() ;
  30. y =*index.begin() ;
  31. y-- ;
  32. if ( x > 1 && y > 1){
  33. break;
  34. }
  35. }
  36. }
  37. cout <<x <<" "<<y << endl;
  38. }
  39. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.