Submission #128344

# Submission time Handle Problem Language Result Execution time Memory
128344 2019-07-10T18:51:44 Z shafinalam Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;
const int mxn = 1e5+5;
typedef long long ll;
vector<int>adj[mxn];
ll sub[mxn];
bool vis[mxn];
ll ans = 0;

void dfs1(int u, int p)
{
    sub[u] = 1;
    vis[u] = 1;
    for(auto v : adj[u])
    {
        if(v==p) continue;
        dfs1(v, u);
        sub[u]+=sub[v];
    }
}
void dfs2(int u, int p, int root)
{
    ans+=((sub[root]-sub[u])*(sub[u]-1)*2);
    for(auto v : adj[u])
    {
        if(v==p) continue;
        dfs2(v, u, root);
    }
}
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            dfs1(i, i);
            dfs2(i, i, i);
        }
    }
    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:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1048580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1048580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 208344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 8116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 8104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1048580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1048580 KB Time limit exceeded
2 Halted 0 ms 0 KB -