답안 #821335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821335 2023-08-11T09:13:14 Z danikoynov Marshmallow Molecules (CCO19_day2problem2) C++14
0 / 25
60 ms 7348 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 5010;
int n, m;
ll len[maxn];
bitset < maxn > edge[maxn];

vector < int > adj[100010];
void solve()
{
    cin >> n >> m;
    /**if (n <= 5000)
    {
    for (int i = 1; i <= m; i ++)
    {
        int a, b;
        cin >> a >> b;
        edge[a][b] = 1;
    }

    int ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= i; j ++)
        {
            edge[i][j] = 0;
        }
        for (int j = i + 1; j <= n; j ++)
        {
            if (edge[i][j] == 1)
            {
                edge[j] |= edge[i];
            }
        }
    }

    for (int i = 1; i <= n; i ++)
    {
        edge[i][i] = 0;
        ans += edge[i].count();
    }



    cout << ans << endl;
    }
    else*/
    {
        for (int i = 1; i <= m; i ++)
        {
            int a, b;
            cin >> a >> b;
            adj[a].push_back(b);
        }

        ll all_edges = m;
        for (int i = n; i > 0; i --)
        {
            ll sum = 0;
            ///cout << "vertex " << i << endl;
            for (int u : adj[i])
            {
                sum += len[u];


            }
            ///cout << sum << endl;
            all_edges += max(0, (int)(adj[i].size()) - 1);
            all_edges += max((ll)0, sum - 1);
            for (int u : adj[i])
            {
                //all_edges += (len[u]) * (sum - len[u]);
                //sum -= len[u];
                len[i] += len[u];
            }
            len[i] ++;
        }
        cout << all_edges << endl;
    }
}

int main()
{
    solve();
    return 0;
}
/**
5 3

1 2
1 3
3 4
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 7348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -