# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
517034 | aurims | Fire drill (LMIO18_sauga) | C++14 | 218 ms | 6308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <array>
#include <list>
#include <iostream>
#include <vector>
#define debug cout << "alion\n"
#define MAX (int)10e3
#define pb push_back
using namespace std;
void test_print(vector<vector<int>> l)
{
for(int i = 0; i < l.size(); i++)
{
cout << "City " << i << ".\n";
for(int j = 0; j < l[i].size(); j++)
cout << l[i][j] << ' ';
cout << '\n';
}
}
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int T, N, S;
cin >> T >> N >> S;
vector<vector<int>> l(N);
for(int i = 0; i < N; i++)
{
int n;
cin >> n;
l[i].resize(n);
for(int j = 0; j < n; j++)
{
cin >> l[i][j];
l[i][j]--;
}
}
vector<int> evac;
int i = 0;
while(evac.size() < N)
{
if(l[i].empty()) // if node has no outgoing edges
{
evac.pb(i); // it can be evacuated freely with no penalties
// delete it from graph
for(int j = 0; j < N; j++)
{
if(j == i) continue;
for(int k = 0; k < l[j].size(); k++)
if(l[j][k] == i)
l[j].erase(l[j].begin()+k);
}
l[i] = {-1};
i = -1;
}
i++;
}
for(const int idx : evac)
cout << idx+1 << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |