Submission #849983

# Submission time Handle Problem Language Result Execution time Memory
849983 2023-09-15T15:18:57 Z nonono Duathlon (APIO18_duathlon) C++14
0 / 100
42 ms 23100 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e5 + 10;

int n, m;
vector<vector<int>> g(mxN), bcc_graph(mxN);
int num[mxN], low[mxN], timer = 0;
stack<int> st;

int siz[mxN << 1];
int bccs = 1;
long long sum = 0;

void tanjan(int u, int par) {
    num[u] = low[u] = ++ timer;
    st.push(u);
    
    for(int v : g[u]) if(v != par) {
        if(num[v]) low[u] = min(low[u], num[v]);
        else {
            tanjan(v, u);
            low[u] = min(low[u], low[v]);
            if(low[v] >= num[u]) {
                bcc_graph[u].push_back(n + bccs);
                
                while(!st.empty() && st.top() != u) {
                    bcc_graph[n + bccs].push_back(st.top());
                    st.pop();
                }  
                
                bccs ++ ;
            }
        }
    }
}

void dfs(int u) {
    siz[u] = (u <= n);
    
    for(int v : bcc_graph[u]) {
        dfs(v);
        
        siz[u] += siz[v];
        if(u > n) sum -= 1LL * bcc_graph[u].size() * siz[v] * (siz[v] - 1);
    }
    
    if(u > n) sum -= 1LL * bcc_graph[u].size() * (n - siz[u]) * (n - siz[u] - 1);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> m;
    
    for(int i = 1; i <= m; i ++) {
        int u, v;
        cin >> u >> v;
        
        g[u].push_back(v);
        g[v].push_back(u);
    }
    
    for(int i = 1; i <= 2 * n; i ++) siz[i] = -1;
    
    for(int i = 1; i <= n; i ++) {
        if(num[i]) continue ;
        
        int prev_timer = timer;
        tanjan(i, 0);
        
        int x = timer - prev_timer;
        sum += x * (x - 1) * (x - 2);
        
        dfs(i);
    }
    
    cout << sum << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 23100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5188 KB Output is correct
2 Correct 3 ms 5184 KB Output is correct
3 Correct 3 ms 5184 KB Output is correct
4 Correct 3 ms 5180 KB Output is correct
5 Correct 4 ms 5180 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Incorrect 2 ms 5212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 21072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Incorrect 3 ms 5212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 21076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -