标签:into esc 输入 编号 mis 编程 The 字典序 之间
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47751 Accepted Submission(s): 18072
#include<bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int> >q; int into[505],n,m,a,b,anss[505],k=0; vector<int> mp[505]; void bfs() { int c=1; while(!q.empty()) { int now=q.top(); q.pop(); if(c!=n) { cout<<now<<" "; c++; } else cout<<now<<endl; for(int i=0;i<mp[now].size();i++) { into[mp[now][i]]--; if(into[mp[now][i]]==0) { q.push(mp[now][i]); } } } } int main() { while(cin>>n>>m) { for(int i=1;i<=n;i++) mp[i].clear(); memset(into,0,sizeof(into)); while(m--) { cin>>a>>b; mp[a].push_back(b); into[b]++; } for(int i=1;i<=n;i++) { if(into[i]==0) { q.push(i); } } bfs(); } }
标签:into esc 输入 编号 mis 编程 The 字典序 之间
原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/12388842.html