제출 #1126563

#제출 시각아이디문제언어결과실행 시간메모리
1126563ntmin철인 이종 경기 (APIO18_duathlon)C++20
0 / 100
1127 ms1114112 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define ON(a, b) (a >> b & 1)
#define all(x) x.begin(), x.end()
template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;}
template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;}

const int N = 1e5 + 1;
int sz[N], n, m; vector<int> g[N]; 
ll ans = 0;

void dfs(int u, int par){
    sz[u] = 1;
    for(int v : g[u]){
        if(v == par) continue;
        dfs(v, u);
        sz[u] += sz[v];
    }
}

void cal(int u, int par, int total){
    ans += 1LL * (total - sz[u]) * (sz[u] - 1) * 2;
    for(int v : g[u]){
        if(v == par) continue;
        cal(v, u, total);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if(fopen("BIKERACE.INP", "r")){
        freopen("BIKERACE.INP", "r", stdin);
        freopen("BIKERACE.OUT", "w", stdout);
    }

    cin >> n >> m;
    for(int i = 0, u, v; i < m; ++i){
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for(int i = 1; i <= n; ++i){
        if(!sz[i]){
            dfs(i, 0);
            cal(i, 0, sz[i]);
        }
    }

    cout << ans;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("BIKERACE.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("BIKERACE.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...