# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
517054 | aurims | Fire drill (LMIO18_sauga) | C++14 | 217 ms | 4304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |