Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int n;
- cin >> n;
- vector<pair<int, int>> edges;
- int matrix[n][n];
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n; j++)
- matrix[i][j] = 0;
- }
- int a, b;
- for (int i = 0; i < n - 1; i++){
- cin >> a >> b;
- matrix[a - 1][b - 1] = 1;
- matrix[b - 1][a - 1] = 1;
- }
- int max_i = 0, max_roads = 0;
- int coun = 0;
- for (int i = 0; i < n; i++){
- coun = 0;
- for (int j = 0; j < n; j++){
- coun += matrix[i][j];
- }
- if (coun > max_roads) {
- max_roads = coun;
- max_i = i + 1;
- }
- }
- cout << max_roads << " " << max_i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement