This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//1610612741, 1000000007
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
ll S1, S2, S3;
int h[N], sz[N];
int n, m;
vi g[N];
void precalc (int v, int p = 0){
h[v] = h[p] + 1;
sz[v] = 1;
for (int to : g[v]){
if (!h[to]){
precalc(to, v);
sz[v] += sz[to];
}
}
}
void calc1 (int v){
for (int to : g[v])
if (h[to] - h[v] == 1)
S1 += 1LL * (n - sz[to] - 1) * sz[to];
S1 += 1LL * (n - sz[v]) * (sz[v] - 1);
for (int to : g[v])
if (h[to] - h[v] == 1)
calc1(to);
}
main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
precalc(1);
calc1(1);
cout << S1;
}
Compilation message (stderr)
count_triplets.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |