# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
517054 | aurims | Fire drill (LMIO18_sauga) | C++14 | 217 ms | 4304 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 <iostream>
#include <vector>
#define debug cout << "alion\n"
#define MAX (int)10e3
#define pb push_back
using namespace std;
/* input with no loops in graph
0 7 1
2 2 3
0
3 4 5 6
0
1 7
0
0
*/
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';
}
}
void evacuate(vector<vector<int>> &l, int ind, vector<int> &e)
{
e.pb(ind);
for(int i = 0; i < l.size(); i++)
{
if(i == ind) continue;
for(int j = 0; j < l[i].size(); j++)
if(l[i][j] == ind)
l[i].erase(l[i].begin()+j);
}
l[ind] = {-1}; // we can't erase the node from the graph since it would change the numerings
}
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;
while(evac.size() < N)
{
// remove all nodes that have no outgoing edges
for(int i = 0; i < l.size(); i++)
{
if(l[i].empty()) // if node has no outgoing edges
{
evacuate(l, i, evac);
i = -1;
}
}
// remove a node with most outgoing edges
int mxe = -1;
int mxind = -1;
for(int i = 0; i < l.size(); i++)
{
if((int)l[i].size() > mxe && l[i][0] != -1)
{
mxe = l[i].size();
mxind = i;
}
}
if(mxind != -1) evacuate(l, mxind, evac);
//getchar();
}
for(const int idx : evac)
cout << idx+1 << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |