답안 #111218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111218 2019-05-14T09:30:11 Z SamAnd 철인 이종 경기 (APIO18_duathlon) C++17
25 / 100
1000 ms 33936 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, m;
vector<int> a[N];

long long ans;

int c[N];
int tin[N], ti;
int fup[N];
set<pair<int, int> > s;
void dfs0(int x, int p)
{
    c[x] = 1;
    fup[x] = tin[x] = ti++;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        if (c[h])
        {
            fup[x] = min(fup[x], tin[h]);
        }
        else
        {
            dfs0(h, x);
            if (tin[x] < fup[h])
            {
                s.insert(m_p(x, h));
                s.insert(m_p(h, x));
            }
            fup[x] = min(fup[x], fup[h]);
        }
    }
}

int k;
void dfs01(int x)
{
    c[x] = k;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (s.find(m_p(x, h)) != s.end())
            continue;
        if (!c[h])
            dfs01(h);
    }
}

int cc[N];
int kk;
void dfs02(int x)
{
    cc[x] = kk;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (!cc[h])
            dfs02(h);
    }
}

vector<int> v[N];

vector<int> t[N];
vector<int> g[N];

int q[N];
void dfs03(int x, int p)
{
    q[x] = v[x].size();
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (h == p)
            continue;
        dfs03(h, x);
        q[x] += q[h];
    }
}

void solv0()
{
    for (int i = 1; i <= n; ++i)
    {
        if (!c[i])
            dfs0(i, i);
    }
    memset(c, 0, sizeof c);
    for (int i = 1; i <= n; ++i)
    {
        if (!c[i])
        {
            ++k;
            dfs01(i);
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (!cc[i])
        {
            ++kk;
            dfs02(i);
        }
    }

    for (set<pair<int, int> >::iterator it = s.begin(); it != s.end(); ++it)
    {
        g[c[(*it).first]].push_back(c[(*it).second]);
        t[(*it).first].push_back((*it).second);
    }

    for (int i = 1; i <= n; ++i)
        v[c[i]].push_back(i);

    for (int m = 1; m <= n; ++m)
    {
        dfs03(c[m], c[m]);

        long long sum = 0;
        for (int i = 0; i < t[m].size(); ++i)
        {
            int h = t[m][i];
            sum += q[c[h]];
        }
        for (int i = 0; i < t[m].size(); ++i)
        {
            int h = t[m][i];
            sum -= q[c[h]];
            ans += (sum * q[c[h]]);
            sum += q[c[h]];
        }

        vector<long long> ysum;
        ysum.assign(v[c[m]].size(), 1);

        for (int i = 0; i < v[c[m]].size(); ++i)
        {
            int x = v[c[m]][i];

            if (x == m)
                continue;

            for (int j = 0; j < t[x].size(); ++j)
            {
                int h = t[x][j];
                ysum[i] += q[c[h]];
            }

            ans += (sum * ysum[i] * 2);
        }

        for (int i = 0; i < v[c[m]].size(); ++i)
        {
            int x = v[c[m]][i];
            if (x == m)
                continue;
            for (int j = 0; j < v[c[m]].size(); ++j)
            {
                int y = v[c[m]][j];
                if (y == m || y == x)
                    continue;
                ans += (ysum[i] * ysum[j]);
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    solv0();
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void dfs0(int, int)':
count_triplets.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs01(int)':
count_triplets.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs02(int)':
count_triplets.cpp:60:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs03(int, int)':
count_triplets.cpp:77:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void solv0()':
count_triplets.cpp:126:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < t[m].size(); ++i)
                         ~~^~~~~~~~~~~~~
count_triplets.cpp:131:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < t[m].size(); ++i)
                         ~~^~~~~~~~~~~~~
count_triplets.cpp:142:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < v[c[m]].size(); ++i)
                         ~~^~~~~~~~~~~~~~~~
count_triplets.cpp:149:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < t[x].size(); ++j)
                             ~~^~~~~~~~~~~~~
count_triplets.cpp:158:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < v[c[m]].size(); ++i)
                         ~~^~~~~~~~~~~~~~~~
count_triplets.cpp:163:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < v[c[m]].size(); ++j)
                             ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10112 KB Output is correct
2 Correct 11 ms 10112 KB Output is correct
3 Correct 12 ms 10112 KB Output is correct
4 Correct 9 ms 10112 KB Output is correct
5 Correct 10 ms 10112 KB Output is correct
6 Correct 10 ms 10112 KB Output is correct
7 Correct 11 ms 10112 KB Output is correct
8 Incorrect 10 ms 10112 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10112 KB Output is correct
2 Correct 11 ms 10112 KB Output is correct
3 Correct 12 ms 10112 KB Output is correct
4 Correct 9 ms 10112 KB Output is correct
5 Correct 10 ms 10112 KB Output is correct
6 Correct 10 ms 10112 KB Output is correct
7 Correct 11 ms 10112 KB Output is correct
8 Incorrect 10 ms 10112 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1068 ms 25176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 10368 KB Output is correct
2 Correct 24 ms 10368 KB Output is correct
3 Correct 25 ms 10368 KB Output is correct
4 Correct 32 ms 10500 KB Output is correct
5 Correct 27 ms 10368 KB Output is correct
6 Correct 30 ms 10368 KB Output is correct
7 Correct 27 ms 10368 KB Output is correct
8 Correct 25 ms 10368 KB Output is correct
9 Correct 26 ms 10368 KB Output is correct
10 Correct 22 ms 10368 KB Output is correct
11 Correct 22 ms 10368 KB Output is correct
12 Correct 18 ms 10368 KB Output is correct
13 Correct 16 ms 10496 KB Output is correct
14 Correct 16 ms 10368 KB Output is correct
15 Correct 13 ms 10284 KB Output is correct
16 Correct 19 ms 10368 KB Output is correct
17 Correct 22 ms 10368 KB Output is correct
18 Correct 20 ms 10368 KB Output is correct
19 Correct 23 ms 10368 KB Output is correct
20 Correct 22 ms 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 33896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10368 KB Output is correct
2 Correct 26 ms 10368 KB Output is correct
3 Correct 18 ms 10240 KB Output is correct
4 Correct 20 ms 10240 KB Output is correct
5 Correct 17 ms 10240 KB Output is correct
6 Correct 13 ms 10240 KB Output is correct
7 Correct 14 ms 10240 KB Output is correct
8 Correct 14 ms 10240 KB Output is correct
9 Correct 13 ms 10240 KB Output is correct
10 Correct 15 ms 10240 KB Output is correct
11 Correct 19 ms 10240 KB Output is correct
12 Correct 23 ms 10380 KB Output is correct
13 Correct 20 ms 10368 KB Output is correct
14 Correct 22 ms 10240 KB Output is correct
15 Correct 20 ms 10368 KB Output is correct
16 Correct 15 ms 10240 KB Output is correct
17 Correct 15 ms 10240 KB Output is correct
18 Correct 14 ms 10240 KB Output is correct
19 Correct 14 ms 10240 KB Output is correct
20 Correct 13 ms 10240 KB Output is correct
21 Correct 23 ms 10368 KB Output is correct
22 Correct 18 ms 10240 KB Output is correct
23 Correct 17 ms 10240 KB Output is correct
24 Correct 18 ms 10240 KB Output is correct
25 Correct 10 ms 10240 KB Output is correct
26 Correct 11 ms 10240 KB Output is correct
27 Correct 12 ms 10240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 33936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10112 KB Output is correct
2 Correct 11 ms 10112 KB Output is correct
3 Correct 12 ms 10112 KB Output is correct
4 Correct 9 ms 10112 KB Output is correct
5 Correct 10 ms 10112 KB Output is correct
6 Correct 10 ms 10112 KB Output is correct
7 Correct 11 ms 10112 KB Output is correct
8 Incorrect 10 ms 10112 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10112 KB Output is correct
2 Correct 11 ms 10112 KB Output is correct
3 Correct 12 ms 10112 KB Output is correct
4 Correct 9 ms 10112 KB Output is correct
5 Correct 10 ms 10112 KB Output is correct
6 Correct 10 ms 10112 KB Output is correct
7 Correct 11 ms 10112 KB Output is correct
8 Incorrect 10 ms 10112 KB Output isn't correct
9 Halted 0 ms 0 KB -