Submission #100581

# Submission time Handle Problem Language Result Execution time Memory
100581 2019-03-12T14:17:18 Z MohamedAhmed0 Network (BOI15_net) C++14
0 / 100
12 ms 12160 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 500005 ;
int n ;

vector< vector<int> >adj(MAX) ;
stack<int>s ;
vector<int>v ;

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


int main()
{
    scanf("%d" , &n) ;
    for(int i = 0 ; i < n-1 ; ++i)
    {
        int x , y ;
        scanf("%d %d" , &x , &y) ;
        adj[x].push_back(y) ;
        adj[y].push_back(x) ;
    }
    int leaves = 0 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(adj[i].size() == 1)
            leaves++;
    }
    int start = -1 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(adj[i].size() > 1)
        {
            start = i ;
            dfs(start , -1) ;
            break;
        }
    }
    int edges = (leaves + 1) / 2 ;
    cout<<edges<<"\n";
    if(edges & 1)
    {
        cout<<v.back()<<" "<<start<<"\n";
        edges-- ;
        v.pop_back();
    }
    for(int i = 0 ; i < v.size()/2 ; ++i)
        cout<<v[i]<<" "<<v[i+edges]<<"\n";
    return 0 ;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < v.size()/2 ; ++i)
                     ~~^~~~~~~~~~~~
net.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d" , &n) ;
     ~~~~~^~~~~~~~~~~
net.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d" , &x , &y) ;
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 12160 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 12160 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 12160 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -