Submission #1098035

# Submission time Handle Problem Language Result Execution time Memory
1098035 2024-10-08T21:24:11 Z AndrijaM Network (BOI15_net) C++17
0 / 100
5 ms 12120 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int maxn=5e5+10;
const int mod=998244353;

vector<int>g[maxn];
vector<int>v;

void dfs(int node,int par)
{
    if(g[node].size()==1)
    {
        v.push_back(node);
        return ;
    }
    for(auto ax:g[node])
    {
        if(ax==par)continue;
        dfs(ax,node);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ///freopen("lexicografic.in","r",stdin);
    ///freopen("lexicografic.out","w",stdout);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        if(g[i].size()!=1)
        {
            dfs(i,-1);
            break;
        }
    }
    vector<pair<int,int>>ans;
    int kol=v.size();
    kol/=2;
    for(int i=0;i<kol;i++)
    {
        ans.push_back({v[i],v[i+kol]});
    }
    if(v.size()%2==1)
    {
        ans.push_back({v[0],v[v.size()-1]});
    }
    cout<<ans.size()<<endl;
    for(auto ax:ans)
    {
        cout<<ax.first<<" "<<ax.second<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12120 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12120 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12120 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -