#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n , m;
vector<int> adj[N];
int sub[N] , ans[N];
void go(int u = 1 , int p = 0){
for(int v : adj[u]){
if(v==p)continue;
go(v , u);
sub[u] += sub[v];
}
sub[u]++;
}
void dfs(int u = 1, int p = 0){
for(int v : adj[u]){
if(v == p)continue;
dfs(v , u);
if(adj[v].size() > 1) ans[u] += sub[v] - 1 + ans[v];
}
}
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1; i < n; ++i){
int u , v; cin >>u >> v;
adj[u].emplace_back(v); adj[v].emplace_back(u);
}
go();
dfs();
int A = 0;
for(int i = 1; i <= n; ++i) A += ans[i];
cout << A * 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
640 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
640 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
98 ms |
13272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
7916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
82 ms |
7916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
640 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
640 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |