Submission #907578

# Submission time Handle Problem Language Result Execution time Memory
907578 2024-01-15T21:35:53 Z codefox Duathlon (APIO18_duathlon) C++14
0 / 100
78 ms 22968 KB
#include<bits/stdc++.h>
    
using namespace std;
    
#define ll long long
#define pii pair<int, int>
    
vector<vector<int>> graph;
vector<int> low;
vector<int> num;
vector<pii> compsize;
stack<int> s;
int c = 0;
int d = 0;

int dfs(int i, int p)
{
    num[i] = low[i] = ++c;
    s.push(i);
    int sz =1;
    int sumcs = 0;
    vector<pii> later;
    for (int ele:graph[i])
    {
        if (ele == p) continue;
        if (!num[ele]) 
        {
            int nsz = dfs(ele, i);
            sz += nsz;
            if (low[ele]==num[i])
            {
                int cs = 1;
                while (s.top() != ele)
                {
                    cs++;
                    s.pop();
                }
                sumcs += cs;
                later.push_back({cs, nsz+1});
                s.pop();
                d++;
            }
            low[i] = min(low[i], low[ele]);
        }
        else low[i] = min(low[i], num[ele]);
    }
    if (num[i]==low[i])
    {
        int cs = 1;
        while (s.top() != i)
        {
            cs++;
            s.pop();
        }
        compsize.push_back({cs+sumcs, sz});
        s.pop();
        d++;
    }
    else
    {
        for (pii ele:later)
        {
            compsize.push_back(ele);
        }
    }
    return sz;
}
    
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n, m;
    cin >> n >> m;
    graph.assign(n, vector<int>());
    low.assign(n, 0);
    num.assign(n, 0);
    
    for (int i =0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> subtree(n, 0);
    
    ll sol = 0;
    for (int i = 0; i < n; i++)
    {
        if (!num[i]) 
        {
            c = 0;
            dfs(i, -1);
            for (pii ele:compsize)
            {
                sol += max(0, ele.first*(ele.first-1)*(ele.first-2));
                sol += max(0, (ele.first-1)*(ele.first-1)*(c-ele.first)*2);
                sol += max(0, ele.first*(ele.second-ele.first)*(c-ele.second)*2);
            }
        }
    }
    cout << sol << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 22968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 8152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 8344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -