7517 | 2024-01-09 13:14:46 | adam | Elágazás nélküli úton levő települések (50 pont) | csharp | Compilation error |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int village_count = 0;
int road_count = 0;
cin >> village_count;
cin >> road_count;
vector<vector<int>> village_tree(village_count, vector<int>(0, 0));
for (int i = 0; i < road_count; i++)
{
int village_id = 0;
int village_to = 0;
cin >> village_id;
cin >> village_to;
village_tree[village_id - 1].push_back(village_to - 1);
village_tree[village_to - 1].push_back(village_id - 1);
}
vector<int> accessible(0, 0);
for (int i = 0; i < village_count; i++)
{
if (village_tree[i].size() != 1)
continue;
bool ended = false;
int previous = i;
int check = village_tree[i][0];
while (!ended)
{
accessible.push_back(check);
if (village_tree[check].size() > 2)
{
ended = true;
}
else
{
if (village_tree[check].size() == 1)
ended = true;
else if (village_tree[check][0] == previous)
check = village_tree[check][1];
else
check = village_tree[check][0];
previous = check;
}
}
}
sort(accessible.begin(), accessible.end());
cout << accessible.size() << "\n";
for (int v : accessible)
{
cout << v+1 << " ";
}
return 0;
}
exit status 1
main.cs(2,0): error CS1024: Wrong preprocess