UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214251#2763. 幻想乡的拜访tonysun0530Compile Error//C++1.4kb2024-11-16 20:28:092024-11-16 23:12:33

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define PII pair<int, int>
#define int long long

using namespace std;

const int N = 1e6 + 10;
const int M = N << 1;
const int mod = 1e9 + 7;

int n;
int h[N], e[M], ne[M], w[N], idx;
int dist[N];
bool st[N];

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

void dijkstra(int s)
{
    memset(dist, 0x3f, sizeof dist);
    dist[s] = 0;
    priority_queue<PII, vector<PII>, greater<PII> > heap;
    heap.push({0, s});

    while (heap.size())
    {
        auto t = heap.top();
        heap.pop();

        int ver = t.second, distance = t.first;

        if (st[ver]) continue;
        st[ver] = true;

        for (int i = h[ver]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (dist[j] > dist[ver] + 1)
            {
                dist[j] = dist[ver] + 1;
                heap.push({dist[j], j});
            }
        }
    }
}

signed main()
{
    memset(h, -1, sizeof h);
    cin >> n;
    for(int i = 1 ; i < n ; i ++ )
    {
        int a, b;
        cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    int ans = 0;
    for(int i = 1 ; i <= n ; i ++ )
    {
        memset(st, 0, sizeof st);
        dijkstra(i);
        for(int j = 1 ; j < i ; j ++ ) ans = (ans + dist[j] * i % mod * j % mod) % mod;
    }
    cout << ans;
    return 0;
}

详细

answer.code: In function 'void dijkstra(long long int)':
answer.code:29:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
     heap.push({0, s});\x0d
              ^
answer.code:29:21: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
     heap.push({0, s});\x0d
                     ^
answer.code:33:14: error: 't' does not name a type
         auto t = heap.top();\x0d
              ^
answer.cod...