# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1126563 | ntmin | Duathlon (APIO18_duathlon) | C++20 | 1127 ms | 1114112 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define ON(a, b) (a >> b & 1)
#define all(x) x.begin(), x.end()
template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;}
template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;}
const int N = 1e5 + 1;
int sz[N], n, m; vector<int> g[N];
ll ans = 0;
void dfs(int u, int par){
sz[u] = 1;
for(int v : g[u]){
if(v == par) continue;
dfs(v, u);
sz[u] += sz[v];
}
}
void cal(int u, int par, int total){
ans += 1LL * (total - sz[u]) * (sz[u] - 1) * 2;
for(int v : g[u]){
if(v == par) continue;
cal(v, u, total);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("BIKERACE.INP", "r")){
freopen("BIKERACE.INP", "r", stdin);
freopen("BIKERACE.OUT", "w", stdout);
}
cin >> n >> m;
for(int i = 0, u, v; i < m; ++i){
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; ++i){
if(!sz[i]){
dfs(i, 0);
cal(i, 0, sz[i]);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |