【求助】20pts
查看原帖
【求助】20pts
889498
Bei_Gua_楼主2023/11/11 15:07

Code:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5;
struct Node{
    int w,v;
    bool operator < (const Node &u)const{
        return w<u.w;
    }
};
int t;
int n,m;
int w[N];
vector<Node> g[N];
signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
        for (int i=1;i<=n;i++)g[i].clear();
        cin>>n>>m;
        for (int i=1;i<=n;i++)cin>>w[i];
        for (int i=1;i<=m;i++){
            int u,v;
            cin>>u>>v;
            g[u].push_back({w[v],v});
        }
        for (int i=1;i<=n;i++){
            sort(g[i].begin(),g[i].end());
            if (g[i].size()==0)cout<<"\n";
            else{
                for (const auto &j:g[i]){
                    cout<<j.v<<" ";
                }
                cout<<"\n";
            }
        }
    }
}
2023/11/11 15:07
加载中...