# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387763 | milleniumEeee | Duathlon (APIO18_duathlon) | C++17 | 50 ms | 7040 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 fastInp ios_base::sync_with_stdio(0); cin.tie(0);
#define pii pair<int, int>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define mk make_pair
#define int long long
using namespace std;
const int MAXN = (int)1e5 + 5;
vector <int> g[MAXN];
int n, m;
int S, C, F;
bool used[MAXN];
bool dfs(int v) {
used[v] = 1;
if (v == F) {
used[v] = 0;
if (!used[C]) {
return false;
} else {
return true;
}
}
bool found = false;
for (int to : g[v]) {
if (!used[to]) {
found |= dfs(to);
if (found) {
used[v] = 0;
return true;
}
}
}
used[v] = 0;
return false;
}
void subtask1() {
int ans = 0;
for (int s = 1; s <= n; s++) {
for (int c = 1; c <= n; c++) {
for (int f = 1; f <= n; f++) {
if (s != c && s != f && c != f) {
S = s;
C = c;
F = f;
if (dfs(s)) {
ans++;
}
}
}
}
}
cout << ans << endl;
exit(0);
}
void subtask3() {
for (int i = 1; i <= n; i++) {
if (szof(g[i]) > 2) {
return;
}
}
int deg[3] = {0, 0, 0};
int l = -1, r = -1;
for (int i = 1; i <= n; i++) {
if (szof(g[i]) == 1) {
if (l == -1) {
l = i;
} else {
r = i;
}
}
deg[szof(g[i])]++;
}
if (deg[1]) {
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (i - 1) * (n - i);
}
cout << ans << endl;
} else {
cout << n * (n - 1) * (n - 2) << endl;
}
exit(0);
}
signed main() {
fastInp;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
if (n <= 10 && m <= 100) {
subtask1();
}
subtask3();
}
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... |