Submission #54049

# Submission time Handle Problem Language Result Execution time Memory
54049 2018-07-02T09:12:49 Z bogdan10bos Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1179648 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

LL ans;
int N, M;
int sz[100005];
vector<int> edg[100005];

void DFS(int nod, int fth = 0)
{
    sz[nod] = 1;
    for(auto nxt: edg[nod])
    {
        if(nxt == fth)  continue;
        DFS(nxt, nod);
        sz[nod] += sz[nxt];
        ans += 1LL * sz[nxt] * (N - sz[nxt] - 1);
    }
    ans += 1LL * (N - sz[nod]) * (sz[nod] - 1);
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        edg[x].push_back(y);
        edg[y].push_back(x);
    }

    DFS(1);

    printf("%lld\n", ans);

    return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1142 ms 1179648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1142 ms 1179648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1109 ms 1179648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 4 ms 1179648 KB
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 65 ms 1179648 KB
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 4 ms 1179648 KB
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 60 ms 1179648 KB
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1142 ms 1179648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1142 ms 1179648 KB Time limit exceeded
2 Halted 0 ms 0 KB -