Submission #262364

#TimeUsernameProblemLanguageResultExecution timeMemory
262364CaroLindaDuathlon (APIO18_duathlon)C++14
0 / 100
79 ms11384 KiB
#include <bits/stdc++.h> #define lp(i,a,b) for(int i = a; i < b ; i++) #define ff first #define ss second #define pb emplace_back #define ll long long #define mk make_pair #define sz(x) x.size() #define pii pair<int,int> #define mkt make_tuple #define debug const int MAXN = 1e5+10 ; using namespace std ; int N , M ; ll sub[MAXN] ; ll resp ; bool vis[MAXN] ; vector<int> adj[MAXN] ; void dfs(int x) { vis[x] = true ; sub[x] = 0LL ; for(auto y : adj[x] ) { if(vis[y]) continue ; dfs(y) ; resp += sub[x] * sub[y] * 2LL ; resp += sub[y] * (sub[y]-1) ; sub[x] += sub[y] ; } sub[x]++ ; } int main() { scanf("%d%d", &N , &M ) ; for(int i = 1 , u , v ; i <= M ; i++ ) { scanf("%d%d", &u, &v ) ; adj[u].pb(v) ; adj[v].pb(u) ; } lp(i,1,N+1) if(!vis[i]) dfs(i) ; printf("%lld\n" , resp ) ; }

Compilation message (stderr)

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