UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213528#573. t2ThySecretCompile Error//C++112.6kb2024-11-12 20:07:392024-11-12 23:22:12

answer

#include <bits/stdc++.h>

using namespace std;

// #define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010;
const int INF = 0x3f3f3f3f;

template<typename Type>
inline void read(Type &res)
{
    res = 0;
    int ch = getchar(), flag = 0;
    while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }

int n, q;
int h[N], e[N << 1], ne[N << 1], w[N << 1], idx;
int sz[N], pre[N], stk[N], top;
vector<PII> g[N];
int ans[N], vis[N];

inline void add(int a, int b, int c) { e[++ idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx; }

int rt(int x) { return pre[x] == x ? x : pre[x] = rt(pre[x]); }

inline void merge(int a, int b)
{
    int pa = rt(a), pb = rt(b);
    if (pa == pb) return;
    sz[pb] += sz[pa], pre[pa] = pb;
}

inline void divide(int x, int a, int b)
{
    g[1].emplace_back(a, b), g[x].emplace_back(a, b);
    for (int i = 2; i <= x / i; i ++)
        if (x % i == 0)
        {
            g[i].emplace_back(a, b);
            if (i != x / i) g[x / i].emplace_back(a, b);
        }
}

signed main()
{
    iota(pre, pre + N, 0);
    for (int i = 1; i < N; i ++) sz[i] = 1;
    // memset(h, -1, sizeof h), idx = -1;
    read(n, q);
    for (int i = 1; i < n; i ++)
    {
        int a, b, c; read(a, b, c);
        add(a, b, c), add(b, a, c);
        divide(c, a, b);
    }

    for (int cur = 1; cur <= n; cur ++)
    {
        for (auto [u, v] : g[cur])
        {
            // stk[++ top] = u, stk[++ top] = v;
            if (vis[u] != cur) vis[u] = cur, stk[++ top] = u;
            if (vis[v] != cur) vis[v] = cur, stk[++ top] = v;
            merge(u, v);
        }
        for (int ver = 1; ver <= top; ver ++)
        {
            if (rt(stk[ver]) == stk[ver])
            {
                ans[cur] += (sz[stk[ver]] * (sz[stk[ver]] - 1)) / 2;
                sz[stk[ver]] = 1;
            }
        }
        while (top) pre[stk[top]] = stk[top], sz[stk[top]] = 1, top --;
    }

    while (q --)
    {
        int x; read(x);
        cout << ans[x] << '\n';
    }

    return 0;
}

详细

answer.code: In function 'int main()':
answer.code:76:19: error: expected unqualified-id before '[' token
         for (auto [u, v] : g[cur])\x0d
                   ^
answer.code:76:19: error: expected ';' before '[' token
answer.code:76:20: error: 'u' was not declared in this scope
         for (auto [u, v] : g[cur])\x0d
                    ^
answer.code:76:23: error: 'v' was not declared in this scope
         for (auto [u, v] : g[cur])\x0d
                       ^
answer.code: In lambda function:
answ...