#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(laipsniai[v] > 1000 ||laip != laipsniai[v]) continue;
laipsniai[v] = inf;
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 |
1 |
Correct |
223 ms |
7200 KB |
Output is correct |
2 |
Partially correct |
2 ms |
332 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
332 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
460 KB |
Output is partially correct |
5 |
Partially correct |
3 ms |
332 KB |
Output is partially correct |
6 |
Partially correct |
4 ms |
460 KB |
Output is partially correct |
7 |
Partially correct |
32 ms |
1916 KB |
Output is partially correct |
8 |
Partially correct |
225 ms |
7456 KB |
Output is partially correct |
9 |
Partially correct |
21 ms |
1128 KB |
Output is partially correct |
10 |
Partially correct |
1 ms |
332 KB |
Output is partially correct |