제출 #1369048

#제출 시각아이디문제언어결과실행 시간메모리
1369048adscoding철인 이종 경기 (APIO18_duathlon)C++20
23 / 100
32 ms14588 KiB
#include <bits/stdc++.h>
#define pb emplace_back
#define SZ(x) ((int)x.size())
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __prine_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        cerr << "  ,  ";
        ++s;
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = {0, (__prine_one(s, args), 0)...};
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, const X &b)
{
    if (b > a)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, const X &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

constexpr int maxn = 1e5 + 3;
int n, m, sz[maxn];
vector<int> g[maxn];

// --------------------------------------------------------------------------------------------


void readInput()
{
    cin >> n >> m;
    FOR(i, 1, m)
    {
        int u, v; cin >> u >> v;
        if (u > v) swap(u, v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
}

namespace subTree
{
    bool approve()
    {
        if (m != n - 1) return false;
        FOR(i, 1, n)
            if (SZ(g[i]) > 2) return false;
        return true;
    }


    bool vis[maxn];
    ll res = 0;

    vector<int> vec;

    void dfs_sz(int u, int p)
    {
        vis[u] = true;
        sz[u] = 1;
        vec.push_back(u);
        for (int v : g[u])
        {
            if (vis[v]) continue;
            dfs_sz(v, u);
            res += 1ll * (sz[u] - 1) * sz[v];
            sz[u] += sz[v];
        }
    }

    void solve()
    {
        FOR(i, 1, n)
        {
            if (vis[i]) continue;
            dfs_sz(i, -1);
            for (int u : vec)
            {
                res += 1ll * (sz[u] - 1) * (SZ(vec) - sz[u]); 
            }
            vec.clear();
        }
        res <<= 1;
        cout << res;
    }
}

namespace AC
{
    void tarjan(int u, int p)
    {

    }

    void solve()
    {

    }
}

void solve()
{
    subTree :: solve();
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:164:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  164 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:165:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  165 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…