답안 #952430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952430 2024-03-23T21:13:49 Z Itamar 철인 이종 경기 (APIO18_duathlon) C++14
31 / 100
110 ms 20592 KB
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define pd pair<double,double>
#include <stack>

const int siz = 1e5 + 1;
int c[siz];
vi fr[siz];
bool vis[siz];
int pad[siz];
vi frt[siz];
ll w[siz];
int sor[siz];
int cum[siz];
void dfs(int i, int so) {
    if (vis[i])return;
    sor[i] = so;
    cum[so]++;
    vis[i] = 1;
    for (int f : fr[i]) {
        if (!vis[f]) {
            pad[f] = i;
            dfs(f,so);
        }
        else if ((f != pad[i]) && (c[i]==i)&&(c[f]==f)) {
            int k = pad[i];
            while (k != f) {
                w[i]++;
                c[k] = i;
                k = pad[k];
            }
            w[i]++;
            c[k] = i;
        }
    }
}
ll ans = 0;
int n, m;
bool vist[siz];
int dfst(int i, int t) {
    vist[i] = 1;
    vll v;
    int sum = w[i];
    for (int f : frt[i]) {
        if (!vist[f]) {
            v.push_back(dfst(f,t));
            sum += v.back();
        }
    }
    v.push_back(t - sum);
    ans += (w[i] * (t - 1)) * (t - 2);
    for (ll k : v) {
        ans -= w[i] * k * (k - 1);
        ans -= k * 2 * (w[i] - 1);
    }
    return sum;
}
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    for (int i = 0; i < n; i++) {
        w[i] = 1;
        c[i] = i;
    }
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            pad[i] = i;
            dfs(i,i);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int f : fr[i]) {
            if (c[i] != c[f]) {
                frt[c[i]].push_back(c[f]);
            }
        }
    }
    for(int i = 0; i < n; i++)if(!vist[c[i]])dfst(c[i],cum[sor[i]]);
    cout << ans;
}
/*
4 3
1 2
2 3
3 4
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 16904 KB Output is correct
2 Correct 62 ms 16720 KB Output is correct
3 Correct 72 ms 17392 KB Output is correct
4 Correct 66 ms 16044 KB Output is correct
5 Correct 65 ms 15068 KB Output is correct
6 Correct 73 ms 16584 KB Output is correct
7 Correct 70 ms 14928 KB Output is correct
8 Correct 72 ms 15352 KB Output is correct
9 Correct 70 ms 13652 KB Output is correct
10 Correct 67 ms 13960 KB Output is correct
11 Correct 72 ms 12380 KB Output is correct
12 Correct 61 ms 12116 KB Output is correct
13 Correct 53 ms 12372 KB Output is correct
14 Correct 53 ms 12112 KB Output is correct
15 Correct 52 ms 11856 KB Output is correct
16 Correct 46 ms 11600 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7516 KB Output is correct
19 Correct 5 ms 7660 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 5 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7000 KB Output is correct
2 Correct 3 ms 7256 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7000 KB Output is correct
6 Correct 2 ms 7004 KB Output is correct
7 Correct 2 ms 7004 KB Output is correct
8 Correct 2 ms 7004 KB Output is correct
9 Correct 2 ms 7004 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 2 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 2 ms 7004 KB Output is correct
20 Correct 2 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 14048 KB Output is correct
2 Correct 73 ms 14068 KB Output is correct
3 Correct 72 ms 13904 KB Output is correct
4 Correct 73 ms 13956 KB Output is correct
5 Correct 73 ms 13908 KB Output is correct
6 Correct 94 ms 20592 KB Output is correct
7 Correct 80 ms 18764 KB Output is correct
8 Correct 81 ms 17332 KB Output is correct
9 Correct 110 ms 16160 KB Output is correct
10 Correct 74 ms 13904 KB Output is correct
11 Correct 73 ms 13908 KB Output is correct
12 Correct 73 ms 13908 KB Output is correct
13 Correct 72 ms 13888 KB Output is correct
14 Correct 68 ms 13764 KB Output is correct
15 Correct 62 ms 13452 KB Output is correct
16 Correct 46 ms 12112 KB Output is correct
17 Correct 62 ms 15568 KB Output is correct
18 Correct 61 ms 15672 KB Output is correct
19 Correct 61 ms 15912 KB Output is correct
20 Correct 63 ms 15276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7000 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Incorrect 2 ms 7004 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 13828 KB Output is correct
2 Correct 77 ms 13904 KB Output is correct
3 Incorrect 99 ms 12880 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7000 KB Output isn't correct
2 Halted 0 ms 0 KB -