Codeforces Round 871 (Div. 4) 1829F - Forever Winter Solution
Problem Link : https://codeforces.com/contest/1829/problem/F
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- std::vector<int> adj[500];
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , m ;
- cin >> n >> m ;
- for ( int i = 0 ; i <= n ; i++) {
- adj[i].clear();
- }
- for ( int i = 1 ; i <= m ; i++) {
- int u , v ;
- cin >> u >> v ;
- adj[u].push_back(v) ;
- adj[v].push_back(u) ;
- }
- int x = 0 , y = 0 ;
- for ( int i = 1 ; i <= n ; i++) {
- set<int>index;
- for ( auto j : adj[i]) {
- index.insert(adj[j].size());
- }
- if ( index.size() == 1 ) {
- x = adj[i].size() ;
- y =*index.begin() ;
- y-- ;
- if ( x > 1 && y > 1){
- break;
- }
- }
- }
- cout <<x <<" "<<y << endl;
- }
- }
No comments