# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197531 | quocnguyen1012 | Duathlon (APIO18_duathlon) | C++14 | 216 ms | 28404 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 fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int base = 131;
const int maxn = 1e5 + 5;
vector<int> adj[maxn], g[maxn * 2];
int N, M;
int nsz = 0;
int sz[2 * maxn], comp = maxn;
int num[maxn], low[maxn];
ll res = 0;
vector<int> ST;
void add(int u, int v)
{
g[u].pb(v); g[v].pb(u);
///cout << u << ' ' << v << '\n';
}
void dfs(int u, int p = -1)
{
ST.pb(u);
static int nTime = 0;
num[u] = low[u] = ++nTime;
++nsz;
for (int v : adj[u]){
if (v == p) continue;
if (num[v]){
low[u] = min(low[u], num[v]);
}
else{
dfs(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= num[u]){
++comp;
add(u, comp);
while(1){
int now = ST.back(); ST.pop_back();
add(now, comp);
if (now == v) break;
}
}
}
}
}
void solve(int u, int p = -1)
{
if (u < maxn) sz[u] = 1;
for (int v : g[u]){
if (v == p) continue;
solve(v, u);
sz[u] += sz[v];
}
if (u < maxn) return;
for (int v : g[u]){
int need;
if (v == p) need = nsz - sz[u];
else need = sz[v];
res -= 1ll * need * (need - 1) * (int(g[u].size()) - 1);
}
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> M;
while (M--){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
for (int i = 1; i <= N; ++i){
if (!num[i]){
nsz = 0;
dfs(i);
res += 1ll * nsz * (nsz - 1) * (nsz - 2);
solve(i);
}
}
cout << res << '\n';
}
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... |