Submission #1358782

#TimeUsernameProblemLanguageResultExecution timeMemory
1358782Charizard2021Dreaming (IOI13_dreaming)C++20
Compilation error
0 ms0 KiB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<bool> visited;
vector<long long> res;
long long dfs(int u, int p){
    long long ans = 0;
    for(pair<int, int> x : adj[u]){
        int v = x.first;
        if(v != p){
            ans = max(ans, dfs(v, u) + x.second);
        }
    }
    return ans;
}
long long dfs2(int u, int p){
    visited[u] = true;
    long long ans = res[u];
    for(pair<int, int> x : adj[u]){
        int v = x.first;
        if(v != p){
            ans = max(ans, dfs2(v, u));
        }
    }
    return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
    adj.resize(N);
    visited.resize(N);
    res.resize(N);
    for(int i = 0; i < M; i++){
        adj[A[i]].push_back(make_pair(B[i], T[i]));
        adj[B[i]].push_back(make_pair(A[i], T[i]));
    }
    for(int i = 0; i < N; i++){
        res[i] = dfs(i, 0);
    }
    vector<long long> thing;
    for(int i = 0; i < n; i++){
        if(!visited[i]){
            thing.push_back(dfs2(i, 0));
        }
    }
    sort(thing.begin(), thing.end());
    reverse(thing.begin(), thing.end());
    if((int)thing.size() > 1){
        return thing[0] + thing[1] + L;
    }
    else{
        return 0;
    }
}

Compilation message (stderr)

dreaming.cpp: In function 'long long int dfs(int, int)':
dreaming.cpp:9:33: error: conversion from 'int' to non-scalar type 'std::pair<int, int>' requested
    9 |     for(pair<int, int> x : adj[u]){
      |                                 ^
dreaming.cpp: In function 'long long int dfs2(int, int)':
dreaming.cpp:20:33: error: conversion from 'int' to non-scalar type 'std::pair<int, int>' requested
   20 |     for(pair<int, int> x : adj[u]){
      |                                 ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:33:28: error: no matching function for call to 'std::vector<int>::push_back(std::pair<int, int>)'
   33 |         adj[A[i]].push_back(make_pair(B[i], T[i]));
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from dreaming.cpp:2:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
dreaming.cpp:34:28: error: no matching function for call to 'std::vector<int>::push_back(std::pair<int, int>)'
   34 |         adj[B[i]].push_back(make_pair(A[i], T[i]));
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
dreaming.cpp:40:24: error: 'n' was not declared in this scope
   40 |     for(int i = 0; i < n; i++){
      |                        ^