답안 #924348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924348 2024-02-08T21:26:56 Z codefox 철인 이종 경기 (APIO18_duathlon) C++14
31 / 100
196 ms 53044 KB
#include<bits/stdc++.h>
    
using namespace std;
    
#define int ll    
#define ll long long
    
vector<vector<int>> graph;
vector<vector<int>> cgraph;
vector<int> comp;
vector<int> art;
vector<int> low;
vector<int> num;
vector<int> vis;
stack<int> s;
int c = 0;
int d = 0;
int root = 0;
int sub = 0;
vector<int> subtree;
vector<ll> compsize;
ll sol = 0;
ll n, m;
    
void dfs(int i, int p)
{
    num[i] = low[i] = ++c;
    s.push(i);
    for (int ele:graph[i])
    {
        if (i==root) sub++;
        if (ele == p) continue;
        if (!num[ele]) 
        {
            dfs(ele, i);
            if (low[ele]>=num[i]) art[i] = 1;
            if (low[ele]==num[i])
            {
                while(s.top() != i)
                {
                    comp[s.top()] = d;
                    compsize[d]++;
                    s.pop();
                }
                comp[i] = d;
                compsize[d]++;
                s.pop();
                d++;
            }
        }
        low[i] = min(low[i], low[ele]);
    }
    if (num[i]==low[i] && comp[i]==-1)
    {
        art[i] = 1;
        while (s.top() != i)
        {
            comp[s.top()] = d;
            compsize[d]++;
            s.pop();
        }
        comp[i] = d;
        compsize[d]++;
        s.pop();
        d++;
    }
}
    
int dfs2(int i)
{
    vis[i] = 1;
    ll ss = 0;
    vector<int> cs;
    for (int ele:cgraph[i])
    {
        if (!vis[ele]) 
        {
            int h = dfs2(ele);
            sol -= compsize[i]*(h-compsize[ele])*(h-compsize[ele]-1);
            sol -= compsize[i]*compsize[ele]*(h-compsize[ele])*2;
            cs.push_back(ele);
            ss+=h;
        }
    }
    for (int ele:cs)
    {
        sol -= compsize[ele]*(sub-ss-compsize[i])*(sub-ss-compsize[i]-1);
        sol -= compsize[ele]*compsize[i]*(sub-ss-compsize[i])*2;
    }
    return ss+compsize[i];
}
    
int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    cin >> n >> m;
    graph.assign(n, vector<int>());
    cgraph.assign(5*n, vector<int>());
    compsize.assign(5*n, 0);
    low.assign(n, 0);
    num.assign(n, 0);
    comp.assign(n, -1);
    art.assign(n, 0);
    vis.assign(5*n, 0);
    subtree.assign(5*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);
    }
    
    for (int i = 0; i < n; i++)
    {
        if (!num[i]) 
        {
            sub = 0;
            root = i;
            c = 0;
            dfs(i, -1);
            subtree[comp[i]] = c;
            sol += max((ll)0, c*(c-1)*(c-2));
            if (sub==1) art[i] = 0;
        }
    }
    
    for (int i = 0; i <n; i++)
    {
        if (art[i])
        {
            compsize[comp[i]]--;
            subtree[d] = subtree[comp[i]];
            comp[i] = d;
            compsize[d] = 1;
            d++;
        }
    }
    for (int i = 0; i <n; i++)
    {
        if (art[i])
        {
            for (int ele:graph[i])
            {
                if (art[ele] && ele > i) 
                {
                    cgraph[comp[i]].push_back(d);
                    cgraph[d].push_back(comp[i]);
                    cgraph[d].push_back(comp[ele]);
                    cgraph[comp[ele]].push_back(d);
                    d++;
                    continue;
                }
                cgraph[comp[i]].push_back(comp[ele]);
                cgraph[comp[ele]].push_back(comp[i]);
            }
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (!vis[comp[i]])
        {
            sub = subtree[comp[i]];
            dfs2(comp[i]);
        }
    }
    cout << sol << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 41084 KB Output is correct
2 Correct 74 ms 41148 KB Output is correct
3 Correct 101 ms 45656 KB Output is correct
4 Correct 83 ms 41800 KB Output is correct
5 Correct 94 ms 42420 KB Output is correct
6 Correct 99 ms 45752 KB Output is correct
7 Correct 103 ms 43088 KB Output is correct
8 Correct 109 ms 43768 KB Output is correct
9 Correct 125 ms 41040 KB Output is correct
10 Correct 93 ms 41080 KB Output is correct
11 Correct 80 ms 37036 KB Output is correct
12 Correct 78 ms 36944 KB Output is correct
13 Correct 83 ms 36688 KB Output is correct
14 Correct 73 ms 36540 KB Output is correct
15 Correct 59 ms 35304 KB Output is correct
16 Correct 61 ms 35152 KB Output is correct
17 Correct 12 ms 29276 KB Output is correct
18 Correct 14 ms 29424 KB Output is correct
19 Correct 12 ms 29276 KB Output is correct
20 Correct 12 ms 29368 KB Output is correct
21 Correct 12 ms 29276 KB Output is correct
22 Correct 12 ms 29436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 41228 KB Output is correct
2 Correct 122 ms 41296 KB Output is correct
3 Correct 120 ms 41332 KB Output is correct
4 Correct 123 ms 41300 KB Output is correct
5 Correct 196 ms 41324 KB Output is correct
6 Correct 141 ms 53044 KB Output is correct
7 Correct 146 ms 49236 KB Output is correct
8 Correct 144 ms 47076 KB Output is correct
9 Correct 171 ms 45396 KB Output is correct
10 Correct 124 ms 41276 KB Output is correct
11 Correct 122 ms 42620 KB Output is correct
12 Correct 122 ms 42712 KB Output is correct
13 Correct 132 ms 42568 KB Output is correct
14 Correct 110 ms 41436 KB Output is correct
15 Correct 98 ms 40020 KB Output is correct
16 Correct 63 ms 36068 KB Output is correct
17 Correct 98 ms 43968 KB Output is correct
18 Correct 112 ms 43584 KB Output is correct
19 Correct 97 ms 43436 KB Output is correct
20 Correct 96 ms 43152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 41468 KB Output is correct
2 Correct 139 ms 41556 KB Output is correct
3 Incorrect 138 ms 40388 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -