We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d2ea748 + fe794a0 commit 65594f0Copy full SHA for 65594f0
khj20006/202512/09 BOJ G4 자벌레 세기.md
@@ -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