6389 | 2023-11-26 15:48:43 | CWM | Tom és Jerry 3 | cpp17 | Forditási hiba |
#include <iostream>
#include <vector>
#include <unordered_set>
#include <queue>
using namespace std;
int main()
{
int t;
cin >> t;
for (size_t x = 0; x < t; x++)
{
int v, tP, jP, k;
cin >> v >> tP >> jP >> k;
tP--;
jP--;
vector<unordered_set<int>> g(v);
vector<vector<int>> oldg(v);
for (size_t i = 0; i < v-1; i++)
{
int a, b;
cin >> a >> b;
a--; b--;
g[a].insert(b);
g[b].insert(a);
oldg[a].push_back(b);
oldg[b].push_back(a);
}
queue<int> toBeRemoved;
queue<pair<int,int>> calcMaxDistance;
int lastRemoved = -1;
for (size_t i = 0; i < v; i++)
{
if (g[i].size() == 1) toBeRemoved.push(i);
}
while (!toBeRemoved.empty()) {
lastRemoved = toBeRemoved.front();
toBeRemoved.pop();
if (g[lastRemoved].size() == 0) break;
int nb = *g[lastRemoved].begin();
g[nb].erase(lastRemoved);
if (g[nb].size() == 1) toBeRemoved.push(nb);
}
calcMaxDistance.push({ lastRemoved,0 });
vector<bool> visitedAlready(v);
int res = 0;
while (!calcMaxDistance.empty()) {
pair<int, int> node = calcMaxDistance.front();
calcMaxDistance.pop();
visitedAlready[node.first] = true;
for (size_t i = 0; i < oldg[node.first].size(); i++)
{
if (!visitedAlready[oldg[node.first][i]]) {
calcMaxDistance.push({ oldg[node.first][i], node.second + 1 });
}
}
if (calcMaxDistance.empty()) {
res = node.second;
}
}
if (res <= k) cout << "IGEN\n";
else {
vector<int> tD(v,-1);
vector<int> jD(v,-1);
queue<int> mD;
mD.push(tP);
tD[tP] = 0;
while (!mD.empty())
{
int nN = mD.front();
mD.pop();
for (size_t i = 0; i < oldg[nN].size(); i++)
{
if (tD[oldg[nN][i]] == -1) {
tD[oldg[nN][i]]=tD[nN]+1;
mD.push(oldg[nN][i]);
}
}
}
mD.push(jP);
jD[jP] = 0;
while (!mD.empty())
{
int nN = mD.front();
mD.pop();
for (size_t i = 0; i < oldg[nN].size(); i++)
{
if (jD[oldg[nN][i]] == -1) {
jD[oldg[nN][i]] = jD[nN] + 1;
mD.push(oldg[nN][i]);
}
}
}
int maxV = INT_MAX;
for (size_t i = 0; i < v; i++)
{
if (tD[i] <= jD[i] + 1) {
maxV = min(maxV, jD[i]);
}
}
if (maxV < k) {
cout << "IGEN\n";
}
else {
cout << "NEM\n";
}
}
}
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:95:36: error: 'INT_MAX' was not declared in this scope
95 | int maxV = INT_MAX;
| ^~~~~~~
main.cpp:5:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
4 | #include <queue>
+++ |+#include <climits>
5 |
Exited with error status 1