답안 #997012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997012 2024-06-11T15:16:14 Z vjudge1 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
52 ms 48328 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 2;
ll ans  = 0;
int num[N + 2], low[N + 2], timer , n , m , scc;
stack < int > st;
vector < int > adj[N + 2] , g[N + 2];
ll sz[N + 2];
void dfs(int u , int p = - 1){
    low[u] = num[u] = ++timer;
    st.push(u);
    for(auto v: adj[u]){
        if(v == p)continue;
        if(!num[v]){
            dfs(v , u);
            low[u] = min(low[u] , low[v]);
            if(low[v] >= num[u]){
                scc ++;
                g[scc].push_back(u);
                g[u].push_back(scc);
                int y;
                do{
                    y = st.top();
                    st.pop();
                    g[y].push_back(scc);
                    g[scc].push_back(y);
                }while(y !=  v);
            }
        }
        else{
            low[u] = min(low[u] , num[v]);
        }
    }
}
ll cal(ll total_square , ll total , ll er){
    total_square -= er * er;
    total -= er;
    return total * total - total_square;
}
ll three_im(ll x , ll z){
    if(x < z)return 0;
    ll k = 1;
    for(ll i = x ;i >= x - z + 1; i --){
        k *= i;
    }
    return k ;
}
void dfs2(int u , int p = - 1){
    if(u <= n)sz[u] ++;
    for(auto v: g[u]){
        if(v == p)continue;
        dfs2(v , u);
        sz[u] += sz[v];
    }
    if(u > n){
        ans -= three_im(g[u].size() - 1, 2) *  (n - sz[u] - 1);
        return ;
    }
    ll oth = n - sz[u] ;
    ll total_square = 0;
    ll total = 0;
    for(auto v: g[u]){
        if(v == p) continue;
        total_square += sz[v] * sz[v];
        total += sz[v];
    }
    total_square += oth * oth;
    total += oth;
    ans -= cal(total_square , total , 0) * 2;
    for(auto v: g[u]){
        if(v == p)continue;
        ans -= cal(total_square , total , sz[v]);
    }
    ans -= cal(total_square , total , oth);
}
void solve() {
    cin >> n >> m;
    scc = n;
    for(int i = 1; i <= m ; i ++){
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    dfs2(1);
    assert(timer == n);
    cout << three_im(n , 3) - ans;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "minrect."
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 25432 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 25432 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 31944 KB Output is correct
2 Correct 44 ms 32128 KB Output is correct
3 Runtime error 49 ms 48328 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 22540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 13144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 22356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 25432 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 25432 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -