4个WA不知道怎么改
#include<bits/stdc++.h>
using namespace std;
const int MAX=1145145;
struct QAQ{int to,nxt;}QWQ[MAX],qwq[MAX];
int n,m,lol[MAX/10]={-1},num=0;
bool b[MAX/10]={false},c[MAX/10]={false};
bool fi(QAQ x,QAQ y){return x.nxt>y.nxt;}
void LOL(int x,int y){
QWQ[num].nxt=lol[x];
QWQ[num].to=y;
lol[x]=num++;
return;
}
void dfs(int x){
b[x]=true;
printf("%d ",x);
for(int i=lol[x];i;i=QWQ[i].nxt){
int y=QWQ[i].to;
if(!b[y])dfs(y);
}
return;
}
void bfs(int x){
queue<int>a;
a.push(x);
printf("%d ",x);
c[x]=true;
while(!a.empty()){
int y=a.front();
a.pop();
for(int i=lol[y];i;i=QWQ[i].nxt){
int z=QWQ[i].to;
if(!c[z]){
a.push(z);
printf("%d ",z);
c[z]=true;
}
}
}
return;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)scanf("%d%d",&qwq[i].to,&qwq[i].nxt);
sort(qwq,qwq+n,fi);
for(int i=0;i<m;i++)LOL(qwq[i].to,qwq[i].nxt);
dfs(1);
cout<<endl;
bfs(1);
return 0;
}