编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#24236 #1144. ddd和猴子 Compile Error 0 0 ms 0 K C++ 11 / 1.1 K YangDavid 2020-04-23 0:07:54
显示原始代码
/*
 * Author       : YangDavid
 * Created Time : 2020年04月22日 星期三 23时55分55秒
 */

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template <typename... Args>
auto ndim(size_t sz0, Args&&... args) {
    if constexpr (sizeof...(args) == 1)
        return vector(sz0, args...);
    else
        return vector(sz0, ndim(args...));
}
const int MAXN = 105501;
vector<int> G[MAXN];
int n, deg[MAXN];
int main() {
    scanf("%d", &n);
    set<pii, greater<pii>> st;
    rep(i, n - 1) {
        static int x, y;
        scanf("%d%d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
        deg[x]++, deg[y]++;
    }
    rep(i, n) st.emplace(deg[i], i);
    ll ans = 0;
    while (!st.empty()) {
        auto [dg, v] = *st.begin();
        if (dg <= 3)
            break;
        ans += 1LL * dg * (dg - 1) - 2 * dg;
        st.erase(st.begin());
        for (auto g : G[v]) {
            st.erase(pii(deg[g], g));
            st.insert(pii(--deg[g], g));
        }
    }
    printf("%lld\n", ans);

    return 0;
}

编译信息

/sandbox/1/a.cpp:11:64: error: 'ndim' function uses 'auto' type specifier without trailing return type
 template<typename... Args> auto ndim(size_t sz0, Args&&... args) {
                                                                ^
/sandbox/1/a.cpp:11:64: note: deduced return type only available with -std=c++14 or -std=gnu++14
/sandbox/1/a.cpp: In function 'auto ndim(size_t, Args&& ...)':
/sandbox/1/a.cpp:12:8: warning: 'if constexpr' only available with -std=c++17 or -std=gnu++17
     if constexpr(sizeof...(args) == 1) return vector(sz0, args...);
        ^~~~~~~~~
/sandbox/1/a.cpp:12:53: error: missing template arguments before '(' token
     if constexpr(sizeof...(args) == 1) return vector(sz0, args...);
                                                     ^
/sandbox/1/a.cpp:13:23: error: missing template arguments before '(' token
     else return vector(sz0, ndim(args...));
                       ^
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:31:14: warning: structured bindings only available with -std=c++17 or -std=gnu++17
         auto [dg, v] = *st.begin();
              ^
/sandbox/1/a.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
/sandbox/1/a.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~