Skip to content

Commit 65594f0

Browse files
authored
Merge pull request #1626 from AlgorithmWithGod/khj20006
[20251209] BOJ / G4 / 자벌레 세기 / 권혁준
2 parents d2ea748 + fe794a0 commit 65594f0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
using ll = long long;
5+
6+
int N;
7+
ll deg[300001]{};
8+
vector<pair<int, int>> edges;
9+
10+
int main(){
11+
cin.tie(0)->sync_with_stdio(0);
12+
13+
cin>>N;
14+
edges.resize(N-1);
15+
for(auto &[a,b] : edges) {
16+
cin>>a>>b;
17+
deg[a]++;
18+
deg[b]++;
19+
}
20+
21+
ll ans = 0;
22+
for(auto [a,b] : edges) if(min(deg[a], deg[b]) >= 3) {
23+
ans += ((deg[a] - 1) * (deg[a] - 2) / 2) * ((deg[b] - 1) * (deg[b] - 2) / 2);
24+
}
25+
cout<<ans;
26+
27+
}
28+
```

0 commit comments

Comments
 (0)