답안 #152949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152949 2019-09-10T16:36:59 Z arnold518 철인 이종 경기 (APIO18_duathlon) C++14
10 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const ll MOD = 1e9+7;

int N, M;
vector<int> adj[MAXN+10];

ll ans=0;
int sz[MAXN+10];
bool vis[MAXN+10];

void dfs1(int now, int bef)
{
    sz[now]=1; vis[now]=1;
    for(int nxt : adj[now])
    {
        if(nxt==bef) continue;
        dfs1(nxt, now);
        sz[now]+=sz[nxt];
    }
}

void dfs2(int now, int bef)
{
    int sum=0;
    for(int nxt : adj[now])
    {
        if(nxt==bef) continue;
        sz[now]-=sz[nxt];
        sz[nxt]+=sz[now];
        dfs2(nxt, now);
        sz[nxt]-=sz[now];
        sz[now]+=sz[nxt];
    }
    for(int nxt : adj[now])
    {
        ans-=(ll)sz[nxt]*sz[nxt]; ans=(ans%MOD+MOD)%MOD;
        sum+=sz[nxt];
    }
    ans+=(ll)sum*sum; ans=(ans%MOD+MOD)%MOD;
}

int main()
{
    int i, j;

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

    for(i=1; i<=N; i++) if(!vis[i])
    {
        dfs1(i, i);
        dfs2(i, i);
    }
    printf("%lld", ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:51:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
count_triplets.cpp:53: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:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 974 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 974 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 266648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2684 KB Output is correct
2 Correct 5 ms 2936 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 5 ms 2808 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 5 ms 2680 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 5 ms 2680 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 6 ms 2776 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 121 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 6 ms 2936 KB Output is correct
3 Execution timed out 1056 ms 1048580 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 81 ms 7680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 974 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 974 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -