| 23145 | 2026-01-16 13:54:54 | PappMatyas | Városnézés | cpp17 | Forditási hiba |
#include <iostream>
#include <vector>
using namespace std;
int INTMAX = 0x7FFFFFFF;
vector<int> solution;
vector<int> maxVals;
vector<int> maxPaths;
vector<int> v;
vector<vector<int>> r;
static void GetSolutionPath(int index)
{
solution.push_back(index + 1);
if (maxPaths[index] != -1)
{
GetSolutionPath(maxPaths[index]);
}
}
static int GoBack(int index)
{
if (maxVals[index] != -1)
{
return maxVals[index];
}
vector<int> backPaths = r[index];
int maxVal = -INTMAX;
int save = 0;
int length = backPaths.size();
for (int i = 0; i < length; i++)
{
int val = GoBack(backPaths[i]);
if (val > maxVal)
{
maxVal = val;
save = backPaths[i];
}
}
maxVals[index] = maxVal + v[index];
maxPaths[index] = save;
return maxVal + v[index];
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
v.push_back(x);
maxPaths.push_back(-1);
maxVals.push_back(-1);
r.push_back(vector<int>());
}
maxVals[0] = v[0];
for (int i = 0; i < m; i++)
{
int from, to;
cin >> from >> to;
r[to - 1].push_back(from - 1);
}
int returnVal = GoBack(n - 1);
cout << returnVal << endl;
GetSolutionPath(n - 1);
reverse(solution.begin(), solution.end());
for (int x : solution)
{
cout << x << " ";
}
}open /var/local/lib/isolate/411/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:72:9: error: 'reverse' was not declared in this scope
72 | reverse(solution.begin(), solution.end());
| ^~~~~~~