Submission #864590

# Submission time Handle Problem Language Result Execution time Memory
864590 2023-10-23T09:42:08 Z vnm06 Duathlon (APIO18_duathlon) C++14
0 / 100
37 ms 19640 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

long long n, m;
vector<int> gr[300005];

long long ans=0, br=0;
bool used[300005], used_br[300005];
long long dp_v[300005];

void find_br(int v)
{
    used_br[v]=1;
    br++;
    int brs=gr[v].size();
    for(int i=0; i<brs; i++)
    {
        if(used_br[gr[v][i]]) continue;
        find_br(gr[v][i]);
    }
}

void dfs(int v)
{
    used[v]=1;
    dp_v[v]=1;
    int brs=gr[v].size();
    long long sumv=0;
    for(int i=0; i<brs; i++)
    {
        if(used[gr[v][i]]) continue;
        dfs(gr[v][i]);
        ans+=dp_v[gr[v][i]]*(br-dp_v[gr[v][i]]-1+sumv);
        sumv+=dp_v[gr[v][i]];
        dp_v[v]+=dp_v[gr[v][i]];
    }
}

void solve_component(int v)
{
    br=0;
    find_br(v);
    dfs(v);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int v, u;
        cin>>v>>u;
        gr[v].push_back(u);
        gr[u].push_back(v);
    }
    for(int i=1; i<=n; i++)
    {
        if(used[i]) continue;
        solve_component(i);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 19640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 13660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -