Submission #113780

# Submission time Handle Problem Language Result Execution time Memory
113780 2019-05-28T08:27:19 Z Mercenary Network (BOI15_net) C++14
0 / 100
12 ms 12032 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 5e5 + 6;

int n , m;
vector<int> leaf , adj[maxn];
void dfs(int u , int v){
    if(adj[u].size() == 1){
        leaf.pb(u);
    }
    for(int c  : adj[u]){
        if(c != v)dfs(c , u);
    }
}

void enter(){
    cin >> n;
    for(int i = 1 ; i < n ; ++i){
        int u , v;cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    enter();
    int root = 0;
    for(int i = 1 ; i <= n ; ++i){
        if(adj[i].size() > 1){
            dfs(i , 0);
            root = i;
            break;
        }
    }
    if(leaf.size() % 2){
        leaf.pb(leaf.back());
    }
    cout << leaf.size() / 2 << '\n';
    for(int i = 0 ; i < leaf.size() / 2 ; ++i){
        cout << leaf[i] << " " << leaf[leaf.size() - i - 1] << '\n';
    }
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < leaf.size() / 2 ; ++i){
                     ~~^~~~~~~~~~~~~~~~~
net.cpp:45:9: warning: variable 'root' set but not used [-Wunused-but-set-variable]
     int root = 0;
         ^~~~
net.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 12 ms 12032 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 12 ms 12032 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 12 ms 12032 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -