Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
reply qq_28476387#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<cstdlib> #include<string> #include<vector> #include<map> #include<queue> using namespace std; vector<int> e[210];// int n,m,in[210],mp[210][210]; int L[210],l;// void topsort() { priority_queue<int> q; l=n;// for(int i=1;i<=n;i++) { if(in[i]==0) q.push(i); } while(!q.empty()) { int x=q.top(); q.pop(); L[x]=l;// l--;// for(int i=0;i<e[x].size();i++) { int v=e[x][i]; if(--in[v]==0) q.push(v); } } } int main() { int tt; scanf("%d",&tt); while(tt--) { memset(in,0,sizeof(in)); memset(mp,0,sizeof(mp)); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) e[i].clear(); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); if(!mp[y][x]) { e[y].push_back(x); in[x]++; mp[y][x]=1; } } topsort(); if(l!=0) printf("-1\n"); else { for(int i=1;i<=n;++i) printf("%d ",L[i]); printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator