답안 #815696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815696 2023-08-08T19:01:24 Z Ozy 철인 이종 경기 (APIO18_duathlon) C++17
23 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a <<  " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli> 

#define MAX 100000

lli n,m,a,b,res;
vector<lli> hijos[MAX+2];
lli tam[MAX+2],m_tam[MAX+2],vis[MAX+2];

void precalcula(lli pos, lli padre){
    vis[pos] = 1;
    tam[pos] = 1;
    for(auto h : hijos[pos]) {
        if (h == padre) continue;
        precalcula(h,pos);
        tam[pos] += tam[h];
    } 
}
void def(lli pos, lli padre, lli val) {
    m_tam[pos] = val;
    for(auto h : hijos[pos]) {
        if (h == padre) continue;
        def(h,pos,val);
    } 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    rep(i,1,m) {
        cin >> a >> b;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
    }
    
    rep(i,1,n) {
        if (vis[i]) continue;
        precalcula(i,0);
        vis[i] = 0;
    }
    rep(i,1,n) if(!vis[i]) def(i,0,tam[i]);

    rep(act,1,n) {
        for (auto h : hijos[act]) {
            if (tam[h] > tam[act]) a = m_tam[act]-tam[act];
            else a = tam[h];
            
            res += a * (m_tam[act] -a -1); 
        }

    }

    cout << res;

    return 0;
}
//tener cuidado con los bosques
# 결과 실행 시간 메모리 Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1102 ms 944200 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 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2676 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 1 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8728 KB Output is correct
2 Correct 33 ms 8652 KB Output is correct
3 Correct 37 ms 8780 KB Output is correct
4 Correct 33 ms 8724 KB Output is correct
5 Correct 32 ms 8712 KB Output is correct
6 Correct 36 ms 11480 KB Output is correct
7 Correct 36 ms 10936 KB Output is correct
8 Correct 35 ms 10272 KB Output is correct
9 Correct 35 ms 9768 KB Output is correct
10 Correct 32 ms 8684 KB Output is correct
11 Correct 36 ms 9912 KB Output is correct
12 Correct 33 ms 9996 KB Output is correct
13 Correct 33 ms 9968 KB Output is correct
14 Correct 30 ms 9548 KB Output is correct
15 Correct 27 ms 9288 KB Output is correct
16 Correct 18 ms 8044 KB Output is correct
17 Correct 23 ms 10084 KB Output is correct
18 Correct 24 ms 10112 KB Output is correct
19 Correct 24 ms 10080 KB Output is correct
20 Correct 23 ms 10188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Runtime error 447 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 8700 KB Output is correct
2 Correct 39 ms 8564 KB Output is correct
3 Runtime error 528 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 473 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -