1 solutions

  • 0
    @ 2026-11-20 10:49:40

    C++ :

    #include <bits/stdc++.h>
    #define N 1005
    using namespace std;
    vector<int> G[N];
    int din[N];
    
    int main(){
        int n,m,u,v;
        cin >> n>>m;
        
        for (int i = 1;i<=m;i++){
            cin >> u >> v;
            G[u].push_back(v);
            din[v] ++;
        }
        
        int mx = 0,mx_id;
        for (int i = 1;i<=n;i++){
            if (!din[i]){
                cout << i << endl;
            }
            if (mx < G[i].size()){
                mx = G[i].size();
                mx_id = i;
            }
        }
        
        cout << mx_id << endl;
        
        sort(G[mx_id].begin(),G[mx_id].end());
        for (auto v:G[mx_id]){
            cout << v << " ";
        }
        
        return 0;
    }
    
    • 1

    Information

    ID
    378
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    5
    Accepted
    2
    Uploaded By