样例能过但是第一个点就WA了
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
long long t,n,m,u,v,head[N],cnt=0;
struct edge{
long long to,nxt;
};
edge e[N];
int cmp(edge a,edge b){
return a.to>b.to;
}
void add(long long u,long long v){
e[cnt].to=v;
e[cnt].nxt=head[u];
head[u]=cnt++;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>t;
for(long long i=1;i<=t;i++){
cin>>n>>m;
memset(e,0,sizeof(e));
cnt=0;
for(long long j=1;j<=n;j++) head[j]=-1;
for(long long j=1;j<=m;j++){
cin>>u>>v;
add(u,v);
}
sort(e+1,e+n+1,cmp);
for(long long j=1;j<=n;j++){
for(int k=head[j];k!=-1;k=e[k].nxt) cout<<e[k].to<<' ';
cout<<endl;
}
}
return 0;
}