# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387957 | NurstanDuisengaliev | Duathlon (APIO18_duathlon) | C++14 | 70 ms | 12792 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>
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int ll
using namespace std;
const int N = (int)1e5 + 123;
int n, m;
vector <int> g[N];
int used[N];
ll ans = 0, LEN = 0;
bool FindC (int v) {
used[v] = 1;
bool yes = 0;
LEN ++;
for (auto to : g[v]) {
if (!used[to]) {
yes |= FindC (to);
}
else if (used[to] == 1) {
yes = 1;
}
}
used[v] = 2;
return yes;
}
main () {
ios_base::sync_with_stdio (0);
cin >> n >> m;
for (int i = 1; i <= m; i ++) {
int u, v;
cin >> u >> v;
g[u].pb (v);
g[v].pb (u);
}
int maxisz = 0;
for (int i = 1; i <= n; i ++) {
maxisz = max (maxisz, sz (g[i]));
}
if (maxisz <= 2) {
for (int i = 1; i <= n; i ++) {
if (!used[i]) {
LEN = 0;
if (FindC (i)) {
ans += ((LEN * 1ll * (LEN - 1) * 1ll * (LEN - 2)) / 3);
}
else {
for (int j = 1; j <= LEN - 2; j ++) {
ans += (LEN - (j + 2) + 1) * 1ll * j;
}
}
}
}
cout << ans;
return 0;
}
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... |