# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
453111 | jurgis | Fire drill (LMIO18_sauga) | C++14 | 1094 ms | 262148 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 <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int n, t, s;
int laipsniai[1001];
vector<int> adj[1001];
vector<int> result;
int isnaudotapak = 0;
const int inf = 1e8;
void toposort(){
priority_queue<pair<int, int> > q;
for(int i = 1; i <= n; i++){
q.push({-laipsniai[i], i});
}
while(!q.empty()){
int v = q.top().second;
int laip = -q.top().first;
q.pop();
if(laip != laipsniai[v]) continue;
result.push_back(v);
for(auto x : adj[v]){
laipsniai[x]--;
q.push({-laipsniai[x], x});
}
}
}
int main()
{
cin>>t>>n>>s;
for(int i=0; i<n; i++){
int num; cin>>num;
laipsniai[i+1] = num;
for(int a=0; a<num; a++){
int u; cin>>u; adj[u].push_back(i+1);
}
}
toposort();
for(auto i: result){
cout<<i<<"\n";
}
}
/* test case
0 4 1
2 2 3
0
1 4
1 1*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |