# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
262361 | CaroLinda | Duathlon (APIO18_duathlon) | C++14 | 84 ms | 12152 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 ;
int sub[MAXN] ;
ll resp ;
bool vis[MAXN] ;
vector<int> adj[MAXN] ;
void dfs(int x)
{
vis[x] = true ;
sub[x] = 1 ;
for(auto y : adj[x] )
{
if(vis[y]) continue ;
dfs(y) ;
sub[x] += sub[y] ;
}
ll tot = (ll)(sub[x] - 1 ) ;
resp += (tot*(tot-1)) ;
}
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |