#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define FOR(i,a,b) for(int i = (a) , _b = (b); i <= _b; ++i)
#define sz(s) (int)(s).size()
#define MASK(x) ((LL)(1)<<(x))
#define BIT(mask,x) (((mask)>>(x))&(1))
template<class X,class Y>
bool maximize(X &x ,Y y){
if (x < y) return x = y , true; else return false;
}
template<class X,class Y>
bool minimize(X &x ,Y y){
if (x > y) return x = y , true; else return false;
}
template<class T>
void compress(vector<T>&data){
sort(data.begin() , data.end());
data.resize(unique(data.begin() , data.end()) - data.begin());
return;
}
template<class X,class Y>
Y Find(vector<X>&data,Y y){
return upper_bound(data.begin() , data.end() , y) - data.begin();
}
const int N = (int) 1e5;
const int M = (int) 2e5;
int x[M + 2] , y[M + 2];
int n , m;
vector<int>ke[N + 2];
void add_canh(int u , int v){
ke[u].push_back(v) , ke[v].push_back(u);
return;
}
namespace subtask1{
bool check(){
return m == n - 1;
}
int sub[N + 2] = {};
LL ans = 0;
void pre_dfs(int u , int p){
sub[u] = 1;
for(auto& v : ke[u]){
if (v == p) continue;
pre_dfs(v , u);
sub[u] += sub[v];
}
return;
}
void dfs(int u , int p){
for(auto& v : ke[u]){
if (v == p) continue;
ans += (LL)sub[v] * (n - sub[v]);
dfs(v,u);
}
return;
}
void main_code(){
pre_dfs(1,0);
dfs(1,0);
ans -= (LL)n*(n-1)/2;
ans *= 2;
cout << ans;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0) ; cout.tie(0) ;
#define name "main"
if (fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
cin >> x[i] >> y[i];
add_canh(x[i] , y[i]);
}
if (subtask1::check()) return subtask1::main_code() , false;
assert(false);
return 0;
}
Compilation message (stderr)
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:80:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:81:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |