답안 #734117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734117 2023-05-01T17:48:31 Z Username4132 철인 이종 경기 (APIO18_duathlon) C++14
23 / 100
1000 ms 1048576 KB
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back

const int MAXN=100010;
int n, m, curSz, si[MAXN];
bool vis[MAXN];
ll ans=0;
vector<int> g[MAXN], roots;

void dfs1(int v){
    vis[v]=true;
    for(int to:g[v]) if(!vis[to]) dfs1(to);
}

void dfs2(int v, int p){
    si[v]=1;
    for(int to:g[v]) if(to!=p){
        dfs2(to, v);
        si[v]+=si[to];
    }
}

void dfs3(int v, int p){
    ll sq=0;
    for(int to:g[v]) if(to!=p){
        sq+=((ll)si[to])*si[to];
        dfs3(to, v);
    }
    sq+=((ll)(curSz-si[v]))*(curSz-si[v]);
    sq=((ll)(curSz-1))*(curSz-1) - sq;
    ans+=sq;
}

int main(){
    scanf("%d %d", &n, &m);
    forn(i, m){
        int a, b; scanf("%d %d", &a, &b); --a, --b;
        g[a].PB(b), g[b].PB(a);
    }

    forn(i, n) if(!vis[i]) dfs1(i), roots.PB(i);
    for(auto ro:roots) dfs2(ro, ro);
    for(auto ro:roots){
        curSz = si[ro];
        dfs3(ro, ro);
    }
    printf("%lld\n", ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:41:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 656 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 656 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 638492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2664 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2660 KB Output is correct
5 Correct 2 ms 2664 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2660 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2664 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2664 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 7596 KB Output is correct
2 Correct 53 ms 7612 KB Output is correct
3 Correct 57 ms 7628 KB Output is correct
4 Correct 53 ms 7500 KB Output is correct
5 Correct 54 ms 7500 KB Output is correct
6 Correct 70 ms 11684 KB Output is correct
7 Correct 70 ms 10244 KB Output is correct
8 Correct 67 ms 9532 KB Output is correct
9 Correct 71 ms 8916 KB Output is correct
10 Correct 53 ms 7604 KB Output is correct
11 Correct 54 ms 7524 KB Output is correct
12 Correct 50 ms 7556 KB Output is correct
13 Correct 53 ms 7684 KB Output is correct
14 Correct 51 ms 7496 KB Output is correct
15 Correct 43 ms 7260 KB Output is correct
16 Correct 26 ms 6348 KB Output is correct
17 Correct 33 ms 7900 KB Output is correct
18 Correct 35 ms 7876 KB Output is correct
19 Correct 39 ms 7892 KB Output is correct
20 Correct 35 ms 7860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Runtime error 559 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 7556 KB Output is correct
2 Correct 58 ms 7508 KB Output is correct
3 Runtime error 670 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 656 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 656 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -