Submission #51729636
Source Code Expand
// LUOGU_RID: 152945660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll MOD=998244353;
// head
const int N=2e5+5;
vector<vector<int>> G(N);
int du[N];
signed main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m;cin>>n>>m;
for(int i=0;i<m;i++) {
int u,v;cin>>u>>v;
G[u].pb(v);
du[v]++;
}
priority_queue<int,vector<int>,greater<int>> Q;
for(int i=1;i<=n;i++) if(!du[i]) Q.push(i);
vector<int> ans;
while(!Q.empty())
{
int now=Q.top();
Q.pop();
ans.pb(now);
for(auto it:G[now]) {if(du[it]==1) Q.push(it);du[it]--;}
}
if(ans.size()!=n) cout<<-1<<endl;
else for(auto it:ans) cout<<it<<" ";
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Restricted Permutation |
| User | gangbengr |
| Language | C++ 17 (gcc 12.2) |
| Score | 400 |
| Code Size | 1000 Byte |
| Status | AC |
| Exec Time | 84 ms |
| Memory | 16196 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:40:18: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
40 | if(ans.size()!=n) cout<<-1<<endl;
| ~~~~~~~~~~^~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 3 ms | 7716 KiB |
| example_01.txt | AC | 3 ms | 7628 KiB |
| test_00.txt | AC | 74 ms | 16192 KiB |
| test_01.txt | AC | 74 ms | 16196 KiB |
| test_02.txt | AC | 34 ms | 11600 KiB |
| test_03.txt | AC | 26 ms | 13824 KiB |
| test_04.txt | AC | 38 ms | 12476 KiB |
| test_05.txt | AC | 84 ms | 16104 KiB |
| test_06.txt | AC | 37 ms | 11372 KiB |
| test_07.txt | AC | 80 ms | 15980 KiB |
| test_08.txt | AC | 33 ms | 14464 KiB |
| test_09.txt | AC | 30 ms | 13896 KiB |
| test_10.txt | AC | 10 ms | 9044 KiB |
| test_11.txt | AC | 29 ms | 11868 KiB |
| test_12.txt | AC | 37 ms | 11628 KiB |
| test_13.txt | AC | 14 ms | 9588 KiB |
| test_14.txt | AC | 31 ms | 11240 KiB |
| test_15.txt | AC | 23 ms | 11072 KiB |
| test_16.txt | AC | 22 ms | 10908 KiB |
| test_17.txt | AC | 24 ms | 10864 KiB |
| test_18.txt | AC | 5 ms | 8236 KiB |
| test_19.txt | AC | 17 ms | 10036 KiB |