Submission #128350

# Submission time Handle Problem Language Result Execution time Memory
128350 2019-07-10T18:58:28 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 Runtime error 983 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 983 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 236428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 7080 KB Output isn't correct
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 104 ms 6904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 983 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 983 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -