Submission #106374

#TimeUsernameProblemLanguageResultExecution timeMemory
106374HideoDuathlon (APIO18_duathlon)C++14
23 / 100
205 ms15480 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define mk make_pair #define pb push_back #define fr first #define sc second #define vi vector < int > #define pii pair < int, int > const int N = 2e5 + 7; const int INF = 1e9 + 7; int sz[N]; int n, m; int ans; vi g[N]; int asd; int as[N]; void dfs (int v = 1, int p = 0){ sz[v] = 1; as[v] = asd; for (int to : g[v]){ if (!sz[to]){ dfs(to, v); sz[v] += sz[to]; } } } main(){ cin >> n >> m; for (int i = 1; i <= m; i++){ int a, b; scanf("%lld%lld", &a, &b); g[a].pb(b); g[b].pb(a); } for (int i = 1; i <= n; i++) { if (!sz[i]) { asd = i; dfs(i); ans -= sz[i] * (sz[i] - 1) / 2; } } for (int i = 1; i <= n; i++) { ans += (sz[i] * (sz[as[i]] - sz[i])); } cout << ans * 2; }

Compilation message (stderr)

count_triplets.cpp:34:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...