답안 #771822

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771822 2023-07-03T09:53:29 Z CyberCow 철인 이종 경기 (APIO18_duathlon) C++17
8 / 100
44 ms 16464 KB
//#include <bits/stdc++.h>
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 300005;
vector<int> v[N];
int color[N];

ll st = 0, sz = 0;

void Dfs(int g, int p)
{
    sz++;
    color[g] = 1;
    for (auto to : v[g])
    {
        if (to != p)
        {
            if (color[to] == 1)
                st = 1;
            else
                Dfs(to, g);
        }
    }
}

void solve()
{
    int n, i, j, x, y, m;
    cin >> n >> m;
    for ( i = 0; i < m; i++)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    ll ans = 0;
    for ( i = 1; i <= n; i++)
    {
        sz = 0; st = 0;
        Dfs(i, -1);
        if (st == 1)
        {
            ans += sz * (sz - 1) * (sz - 2);
        }
        else if(sz >= 3)
        {
            ans += sz * (sz - 1) * (sz - 2) / 3;
        }
    }
    cout << ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void solve()':
count_triplets.cpp:51:15: warning: unused variable 'j' [-Wunused-variable]
   51 |     int n, i, j, x, y, m;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Incorrect 4 ms 7252 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Incorrect 4 ms 7252 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 16464 KB Output is correct
2 Correct 40 ms 16240 KB Output is correct
3 Correct 32 ms 13952 KB Output is correct
4 Correct 40 ms 15132 KB Output is correct
5 Correct 43 ms 13244 KB Output is correct
6 Correct 33 ms 13200 KB Output is correct
7 Correct 36 ms 12528 KB Output is correct
8 Correct 44 ms 12936 KB Output is correct
9 Correct 31 ms 12028 KB Output is correct
10 Correct 32 ms 12480 KB Output is correct
11 Correct 33 ms 11576 KB Output is correct
12 Correct 36 ms 11508 KB Output is correct
13 Correct 35 ms 11400 KB Output is correct
14 Correct 25 ms 11344 KB Output is correct
15 Correct 30 ms 10956 KB Output is correct
16 Correct 21 ms 10916 KB Output is correct
17 Correct 4 ms 7756 KB Output is correct
18 Correct 4 ms 7764 KB Output is correct
19 Correct 4 ms 7728 KB Output is correct
20 Correct 5 ms 7760 KB Output is correct
21 Correct 4 ms 7764 KB Output is correct
22 Correct 4 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 11548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 10984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Incorrect 4 ms 7252 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Incorrect 4 ms 7252 KB Output isn't correct
8 Halted 0 ms 0 KB -