답안 #370662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370662 2021-02-24T12:49:59 Z Leonardo_Paes 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> pii;
#define f first
#define s second
const int maxn = 1e5+10;
vector<int> grafo[maxn];
int n, m, dp[maxn], sz[maxn], qtd2[maxn];
int solve(int u, int p = 0){ // lca of path is u, 1 as a root
    int ans = 0; // sum of dps
    sz[u] = 1;
    for(int v : grafo[u]){
        if(v == p) continue;
        ans += solve(v, u);
        sz[u] += sz[v];
        qtd2[u] += qtd2[v] + sz[v];
    }
    int qtd = sz[u] - 1;
    for(int v : grafo[u]){
        if(v == p) continue;
        qtd -= sz[v];
        dp[u] += sz[v] * qtd;
        dp[u] += (sz[u]  - sz[v]) * qtd2[v];
    }
    return ans + dp[u];
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int u, v;
        cin >> u >> v;
        grafo[u].push_back(v);
        grafo[v].push_back(u);
    }
    cout << 2*solve(1) << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1114 ms 424300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 3 ms 2924 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Incorrect 2 ms 2796 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10092 KB Output is correct
2 Correct 63 ms 9964 KB Output is correct
3 Correct 63 ms 9964 KB Output is correct
4 Correct 66 ms 9964 KB Output is correct
5 Correct 69 ms 10108 KB Output is correct
6 Correct 74 ms 13676 KB Output is correct
7 Correct 84 ms 12780 KB Output is correct
8 Correct 75 ms 12012 KB Output is correct
9 Correct 66 ms 11372 KB Output is correct
10 Incorrect 74 ms 9964 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Runtime error 712 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10092 KB Output is correct
2 Correct 77 ms 9936 KB Output is correct
3 Runtime error 863 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -