# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106374 | Hideo | Duathlon (APIO18_duathlon) | C++14 | 205 ms | 15480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pii pair < int, int >
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
int sz[N];
int n, m;
int ans;
vi g[N];
int asd;
int as[N];
void dfs (int v = 1, int p = 0){
sz[v] = 1;
as[v] = asd;
for (int to : g[v]){
if (!sz[to]){
dfs(to, v);
sz[v] += sz[to];
}
}
}
main(){
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b;
scanf("%lld%lld", &a, &b);
g[a].pb(b);
g[b].pb(a);
}
for (int i = 1; i <= n; i++) {
if (!sz[i]) {
asd = i;
dfs(i);
ans -= sz[i] * (sz[i] - 1) / 2;
}
}
for (int i = 1; i <= n; i++) {
ans += (sz[i] * (sz[as[i]] - sz[i]));
}
cout << ans * 2;
}
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... |