제출 #155494

#제출 시각아이디문제언어결과실행 시간메모리
155494AkashiDuathlon (APIO18_duathlon)C++14
100 / 100
169 ms27288 KiB
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

int n, m, nr, nrc;
bool f[100005], viz[200005], art[100005];
int h[100005], low[100005], d[200005];
vector <int> v[100005];
vector <int> v2[200005];
stack <int> st;
long long Sol;

int dfs(int nod, int papa = 0){
    f[nod] = 1;
    st.push(nod);
    ++nr;

    int cnt = 0;
    for(auto it : v[nod]){
        if(papa == it) continue ;

        if(!f[it]){
            ++cnt;
            h[it] = low[it] = h[nod] + 1;
            dfs(it, nod);

            low[nod] = min(low[nod], low[it]);
            if(low[it] >= h[nod]){
                ++nrc;
                v2[nod].push_back(nrc + n);
                while(v2[nrc + n].empty() || v2[nrc + n].back() != it){
                    v2[nrc + n].push_back(st.top());
                    st.pop();
                }
            }
        }
        else low[nod] = min(low[nod], h[it]);
    }
}

void bdfs(int nod){
    viz[nod] = 1;

    if(nod <= n) d[nod] = 1;

    for(auto it : v2[nod]){
        if(viz[it]) continue ;
        bdfs(it);

        d[nod] += d[it];
        if(nod > n) Sol = Sol - 1LL * v2[nod].size() * d[it] * (d[it] - 1);
    }

    if(nod > n) Sol = Sol - 1LL * (nr - d[nod]) * (nr - d[nod] - 1) * v2[nod].size();
}

int main()
{
//    freopen("1.in", "r", stdin);
//    freopen("1.out", "w", stdout);
    scanf("%d%d", &n, &m);

    int x, y;
    for(int i = 1; i <= m ; ++i){
        scanf("%d%d", &x, &y);

        v[x].push_back(y);
        v[y].push_back(x);
    }

    for(int i = 1; i <= n ; ++i){
        if(f[i]) continue ;
        nr = 0;
        dfs(i);
        Sol = Sol + 1LL * nr * (nr - 1) * (nr - 2);

        if(nr > 2) bdfs(i);
    }

    printf("%lld", Sol);

    return 0;
}







컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int dfs(int, int)':
count_triplets.cpp:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...