Submission #741613

# Submission time Handle Problem Language Result Execution time Memory
741613 2023-05-14T13:18:01 Z vjudge1 Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
int travelTime(int N, int M, int L, vector<int> A, vector<int> B, vector<int> T) {
    priority_queue<pair<int, int> > pq;
    vector<vector<pair<int, int> > > ng(N);
    for (int i = 0; i < M; i++) {
        ng[A[i]].push_back(make_pair(B[i], T[i]));
        ng[B[i]].push_back(make_pair(A[i], T[i]));
    }
    vector<int> zeros(N);
    vector<int> nc(N);
    for (int i = 0; i < N; i++) {
        nc[i] = ng[i].size();
        if (nc[i] == 1) {
            pq.push(make_pair(0, i));
        } else if (nc[i] == 0) {
            zeros[i] = true;
        }
    }
    vector<int> vis(N);
    vector<int> dis(N);
    while (!pq.empty()) {
        int f = pq.top().first;
        int s = pq.top().second;
        pq.pop();
        if (nc[s] == 0)continue;
        vis[s] = true;
        for (int i = 0; i < ng[s].size(); i++) {
            int neg = ng[s][i].first;
            int ds = ng[s][i].second;
            if (vis[neg])continue;
            dis[neg] = max(dis[neg], dis[s] + ds);
            if (nc[neg] == 2) {
                pq.push(make_pair(-dis[neg], neg));
            } else if (nc[neg] == 1) {
                zeros[neg] = 1;
            }
            nc[neg]--;
        }
    }
    int rez = 0;
    vector<int> vals;
    for (int i = 0; i < N; i++) {
        if (!zeros[i])continue;
        vals.push_back(dis[i]);
    }
    sort(vals.begin(), vals.end());
    reverse(vals.begin(), vals.end());
    rez = vals[0] + vals[1] + L;
    if (vals.size() > 2) rez = max(rez, vals[1] + vals[2] + L + L);
    return rez;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
dreaming.cpp:28:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (int i = 0; i < ng[s].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
dreaming.cpp:23:13: warning: unused variable 'f' [-Wunused-variable]
   23 |         int f = pq.top().first;
      |             ^
/usr/bin/ld: /tmp/ccZtnVCQ.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status