답안 #260894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260894 2020-08-11T07:11:27 Z SorahISA 철인 이종 경기 (APIO18_duathlon) C++17
8 / 100
62 ms 4856 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false), cin.tie(0)

const int maxn = 1E5 + 5;

vector<int> p(maxn), sz(maxn, 1);

int R(int x) {return x ^ p[x] ? p[x] = R(p[x]) : x;}
void U(int x, int y) {if (R(x) ^ R(y)) sz[R(y)] += sz[R(x)], p[R(x)] = R(y);}

int32_t main() {
    fastIO();
    iota(ALL(p), 0);
    
    int n, m, ans = 0;
    cin >> n >> m;
    
    int u[m], v[m];
    for (int i = 0; i < m; ++i) {
        cin >> u[i] >> v[i], U(u[i], v[i]);
    }
    
    map<int, int> cnt;
    for (int i = 0; i < m; ++i) {
        ++cnt[R(u[i])];
    }
    
    for (auto [idx, val] : cnt) {
        if (val == sz[idx]) ans += sz[idx] * (sz[idx] - 1) * (sz[idx] - 2);
        else ans += sz[idx] * (sz[idx] - 1) * (sz[idx] - 2) / 3;
    }
    
    cout << ans << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3448 KB Output is correct
2 Correct 42 ms 3512 KB Output is correct
3 Correct 41 ms 3452 KB Output is correct
4 Correct 47 ms 3448 KB Output is correct
5 Correct 39 ms 3448 KB Output is correct
6 Correct 38 ms 3448 KB Output is correct
7 Correct 43 ms 3448 KB Output is correct
8 Correct 41 ms 3448 KB Output is correct
9 Correct 41 ms 3448 KB Output is correct
10 Correct 40 ms 3448 KB Output is correct
11 Correct 62 ms 4728 KB Output is correct
12 Correct 53 ms 4472 KB Output is correct
13 Correct 51 ms 4856 KB Output is correct
14 Correct 52 ms 4600 KB Output is correct
15 Correct 42 ms 4720 KB Output is correct
16 Correct 37 ms 4600 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 3508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -