Submission #486548

#TimeUsernameProblemLanguageResultExecution timeMemory
486548Killer2501Network (BOI15_net)C++14
18 / 100
1 ms716 KiB
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "test"
#define pii pair<ll, pll>
using namespace std;
using ll = long long ;
const int  N = 1e2+5;
const ll mod = 1e9+7;
const ll base = 350;
const ll inf = 1e15;
ll m, n, t, k, a[N][N], b[N][N], ans, tong, d[N];
pll trave[N];
vector<ll> kq;
vector<ll> adj[N];
bool ok[N];
string s;
map<ll, ll> mp[N];
void add(ll& x, ll y, ll md)
{
	x += y;
	if(x >= md)x -= md;
}
ll pw(ll k, ll n, ll md)
{
	ll total = 1;
	for(; n; n >>= 1)
	{
		if(n&1)total = total * k % md;
		k = k * k % md;
	}
	return total;
}
void dfs(ll u, ll p)
{
	for(ll v: adj[u])
	{
		if(v == p)continue;
		dfs(v, u);
	}
	if(adj[u].size() == 1)kq.pb(u);
}
void sol()
{
    cin >> n;
    for(int i = 1; i < n; i ++)
	{
		ll x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(1, 0);
	m = kq.size();
	cout << (m+1)/2 << '\n';
	for(int i = 0; i < m/2; i ++)cout << kq[i] <<" "<<kq[i+m/2] << '\n';
	if(m&1)cout << kq[m/2] <<" "<<kq.back();
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...