Submission #152952

#TimeUsernameProblemLanguageResultExecution timeMemory
152952arnold518Duathlon (APIO18_duathlon)C++14
23 / 100
1112 ms1048580 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N, M; vector<int> adj[MAXN+10]; ll ans=0; int sz[MAXN+10]; bool vis[MAXN+10]; void dfs1(int now, int bef) { sz[now]=1; vis[now]=1; for(int nxt : adj[now]) { if(nxt==bef) continue; dfs1(nxt, now); sz[now]+=sz[nxt]; } } void dfs2(int now, int bef) { int sum=0; for(int nxt : adj[now]) { if(nxt==bef) continue; sz[now]-=sz[nxt]; sz[nxt]+=sz[now]; dfs2(nxt, now); sz[nxt]-=sz[now]; sz[now]+=sz[nxt]; } for(int nxt : adj[now]) { ans-=(ll)sz[nxt]*sz[nxt]; sum+=sz[nxt]; } ans+=(ll)sum*sum; } int main() { int i, j; scanf("%d%d", &N, &M); for(i=1; i<=M; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } for(i=1; i<=N; i++) if(!vis[i]) { dfs1(i, i); dfs2(i, i); } printf("%lld", ans); }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:50:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
count_triplets.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
#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...