답안 #864592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864592 2023-10-23T09:48:00 Z vnm06 철인 이종 경기 (APIO18_duathlon) C++14
23 / 100
40 ms 19788 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]]*sumv;
        sumv+=dp_v[gr[v][i]];
        dp_v[v]+=dp_v[gr[v][i]];
    }
    ans+=sumv*(br-sumv-1);
}

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<<2*ans<<endl;
    return 0;
}
/**
8 7
1 2
2 3
2 4
3 5
5 6
6 7
6 8
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 19788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8024 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8024 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8280 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 13412 KB Output is correct
2 Correct 30 ms 14684 KB Output is correct
3 Correct 40 ms 15024 KB Output is correct
4 Correct 30 ms 14676 KB Output is correct
5 Correct 29 ms 14776 KB Output is correct
6 Correct 38 ms 18000 KB Output is correct
7 Correct 32 ms 16952 KB Output is correct
8 Correct 31 ms 16328 KB Output is correct
9 Correct 31 ms 15708 KB Output is correct
10 Correct 28 ms 14676 KB Output is correct
11 Correct 39 ms 14912 KB Output is correct
12 Correct 30 ms 14676 KB Output is correct
13 Correct 29 ms 14684 KB Output is correct
14 Correct 25 ms 14676 KB Output is correct
15 Correct 23 ms 14428 KB Output is correct
16 Correct 16 ms 13396 KB Output is correct
17 Correct 21 ms 15052 KB Output is correct
18 Correct 21 ms 14988 KB Output is correct
19 Correct 21 ms 15044 KB Output is correct
20 Correct 21 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Incorrect 2 ms 8024 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 13396 KB Output is correct
2 Correct 31 ms 14672 KB Output is correct
3 Incorrect 33 ms 14932 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -