답안 #59313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59313 2018-07-21T13:34:15 Z MatheusLealV 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
157 ms 9940 KB
#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";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 9940 KB Output is correct
2 Correct 137 ms 9940 KB Output is correct
3 Correct 111 ms 9940 KB Output is correct
4 Correct 157 ms 9940 KB Output is correct
5 Correct 126 ms 9940 KB Output is correct
6 Correct 140 ms 9940 KB Output is correct
7 Correct 124 ms 9940 KB Output is correct
8 Correct 112 ms 9940 KB Output is correct
9 Correct 97 ms 9940 KB Output is correct
10 Correct 99 ms 9940 KB Output is correct
11 Incorrect 104 ms 9940 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 9940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 9940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -