标签:define its use long spl target nbsp opened show
板题:多组输入,没初始化
#include<bits/stdc++.h> using namespace std; #define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++) #define per(i,j,k) for(int i=(int)k;i>=(int)j;i--) #define pb push_back #define pf push_front #define fi first #define se second 11 typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db; const db PI=acos(-1.0); const ll INF=0x3f3f3f3f3f3f3f3fLL; const int inf=0x3f3f3f3f;//0x7fffffff; const double eps=1e-9; const ll MOD=9999991; const int maxn=1e3+5; vector<int>e[maxn]; int in[maxn]; int n,m; void solve(){ priority_queue<int,vector<int>,greater<int> >Q; vector<int>ans; for(int i=1;i<=n;i++){ if(in[i]==0)Q.push(i); } while(!Q.empty()){ int t=Q.top();Q.pop(); ans.pb(t); for(int i=0;i<e[t].size();i++){ int y=e[t][i]; in[y]--; if(in[y]==0)Q.push(y); } } int len=ans.size(); // cout<<len<<endl; for(int i=0;i<len-1;i++) printf("%d ",ans[i]); printf("%d\n",ans[len-1]); } int main(){ while(cin>>n>>m){ for(int i=1;i<=n;i++)e[i].clear(); rep(i,1,n)in[i]=0; while(m--){ int a,b; scanf("%d %d",&a,&b); e[a].pb(b); in[b]++; } solve(); } // system("pause"); return 0; }
标签:define its use long spl target nbsp opened show
原文地址:https://www.cnblogs.com/littlerita/p/12395407.html