| 19992 | 2025-12-30 21:51:25 | VargaVivien | Városnézés | cpp17 | Forditási hiba |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct ut
{
int bol, ba;
};
bool latogatas(int varos, int *latvanyossag, int *db, vector<vector<int>> terkep, int n, vector<int> &szam)
{
bool vege = false;
vector<int> maximum;
vector<int> temp;
int maxi = 0;
// cout << "szam" << &szam << endl;
// cout << "temp" << &temp << endl;
if(varos == n)
{
vege = true;
*db += latvanyossag[varos - 1];
szam.push_back(varos);
return vege;
}
else
{
int reszdb;
//szam.push_back(varos);
for(int i = 0; i < terkep[varos].size(); i++)
{
reszdb = *db + latvanyossag[varos - 1];
temp.clear();
if(latogatas(terkep[varos][i], latvanyossag, &reszdb, terkep, n, temp))
{
vege = true;
if(reszdb > maxi)
{
maxi = reszdb;
maximum.clear();
maximum=temp;
}
}
}
if(!vege)
{
szam.pop_back();
}
else
{
//szam.insert(szam.end(), maximum.begin(), maximum.end());
szam=maximum;
szam.push_back(varos);
}
*db = maxi;
return vege;
}
}
int main()
{
int n, m;
ut x;
cin >> x.bol >> x.ba;
n = x.bol;
m = x.ba;
int numbers[n];
for(int i=0; i<n; i++) cin >> numbers[i];
vector <vector<int>> terkep(n+1);
for(int i = 0; i < m; i++)
{
cin >> x.bol >> x.ba;
terkep[x.bol].push_back(x.ba);
}
int db = 0;
vector<int> szam;
if (latogatas(1, numbers, &db, terkep, n, szam))
{
cout << db << endl;
//cout << szam.size()<< endl;
for (int j=szam-1; j>=0;j--)
{
cout << szam[j] << " ";
}
}
else
{
cout << -1 << endl;
}
return 0;
}
open /var/local/lib/isolate/405/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:89:24: error: no match for 'operator-' (operand types are 'std::vector<int>' and 'int')
89 | for (int j=szam-1; j>=0;j--)
| ~~~~^~
| | |
| | int
| std::vector<int>
In file included from /usr/include/c++/12/string:47,
from /usr/include/c++/12/bits/locale_classes.h:40,
from /usr/include/c++/12/bits/ios_base.h:41,
from /usr/include/c++/12/ios:42,
from /usr/include/c++/12/ostream:38,
from /usr/include/c++/12/iostream:39,
from main.cpp:1:
/usr/include/c++/12/bits/stl_iterator.h:621:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
621 | operator-(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:621:5: note: template argument deduction/substitution failed:
main.cpp:89:25: note: 'std::vector<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
89 | for (int j=szam-1; j>=0;j--)
| ^
/usr/include/c++/12/bits/stl_iterator.h:1778:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
1778 | operator-(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:1778:5: note: template argument deduction/substitution failed:
main.cpp:89:25: note: 'std::vector<int>' is not derived from 'const std::move_iterator<_IteratorL>'
89 | for (int j=szam-1; j>=0;j--)
| ^