Submission #59313

#TimeUsernameProblemLanguageResultExecution timeMemory
59313MatheusLealVDuathlon (APIO18_duathlon)C++17
0 / 100
157 ms9940 KiB
#include <bits/stdc++.h>
#define N 100050
using namespace std;
typedef long long ll;
ll n, m, c, ans, ok[N];
   
vector<ll> grafo[N];
 
ll sz[N], tot = 0;

ll ultimo;
  
void dfs(ll x)
{
    ultimo = x;

	tot ++;

	ok[x] = 1;

	for(auto v: grafo[x])
	{
		if(ok[v]) continue;

		dfs(v);
	}
}
  
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
  
    cin>>n>>m;    
  
    for(ll i = 1, a, b; i <= m; i++)
    {
        cin>>a>>b;
   
        grafo[a].push_back(b);
  
        grafo[b].push_back(a);
    }

    for(int i = 1; i <= n; i++)
    {
    	if(ok[i]) continue;

    	tot = 0LL;

        ultimo = 0;

    	dfs(i);

        ll ciclo = 0;

        for(auto v: grafo[ultimo])
        {
            if(v == i) ciclo = 1;
        }

       // cout<<i<<" "<<tot<<" "<<ciclo<<" "<<ans<<"\n";

    	if(tot > 2 and ciclo) ans += (tot * (tot - 1) * (tot - 2));

        else if(tot > 2 and !ciclo) ans += (tot * (tot - 1) * (tot - 2))/3;
    }

    cout<<ans<<"\n";
}
#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...