# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152952 | arnold518 | Duathlon (APIO18_duathlon) | C++14 | 1112 ms | 1048580 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N, M;
vector<int> adj[MAXN+10];
ll ans=0;
int sz[MAXN+10];
bool vis[MAXN+10];
void dfs1(int now, int bef)
{
sz[now]=1; vis[now]=1;
for(int nxt : adj[now])
{
if(nxt==bef) continue;
dfs1(nxt, now);
sz[now]+=sz[nxt];
}
}
void dfs2(int now, int bef)
{
int sum=0;
for(int nxt : adj[now])
{
if(nxt==bef) continue;
sz[now]-=sz[nxt];
sz[nxt]+=sz[now];
dfs2(nxt, now);
sz[nxt]-=sz[now];
sz[now]+=sz[nxt];
}
for(int nxt : adj[now])
{
ans-=(ll)sz[nxt]*sz[nxt];
sum+=sz[nxt];
}
ans+=(ll)sum*sum;
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=M; i++)
{
int u, v;
scanf("%d%d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
for(i=1; i<=N; i++) if(!vis[i])
{
dfs1(i, i);
dfs2(i, i);
}
printf("%lld", ans);
}
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... |