Submission #639532

# Submission time Handle Problem Language Result Execution time Memory
639532 2022-09-10T13:39:20 Z zordeno Network (BOI15_net) C++17
0 / 100
5 ms 12128 KB
#include <bits/stdc++.h>

using namespace std;
#define     endl            '\n'
#define     ll              long long

const ll MOD = 1e9 + 7, MAX = 5e5 + 5, INF = 1e18;

vector <int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector <int> dy = { 0, 1, -1, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

vector <ll> adj[MAX];
vector <bool> vis(MAX);
vector <ll> ans;
void dfs(ll node)
{
	if (adj[node].size() == 1)
	{
		ans.push_back(node);
	}
	vis[node] = true;
	for (auto child : adj[node])
	{
		if (!vis[child])
		{
			dfs(child);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		ll u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0);
	cout << ceil(ans.size() * 1.0 / 2.0) << endl;
	for (ll i = 0; i < ans.size() / 2; i++)
	{
		cout << ans[i] + 1 << " " << ans[ans.size() - i - 1] + 1 << endl;
	}
	if (ans.size() % 2 != 0)
	{
		cout << ans[ans.size() / 2] + 1 << " 1" << endl;
	}
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:51:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for (ll i = 0; i < ans.size() / 2; i++)
      |                 ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12116 KB Output is correct
2 Incorrect 5 ms 12128 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12116 KB Output is correct
2 Incorrect 5 ms 12128 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12116 KB Output is correct
2 Incorrect 5 ms 12128 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -