답안 #356181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
356181 2021-01-23T08:00:00 Z nikita4109 Network (BOI15_net) C++17
0 / 100
8 ms 12140 KB
#include <bits/stdc++.h>

using namespace std;

random_device rd;
mt19937 rnd(rd());
#define pt pair<int, int>
#define x first
#define y second
#define what_is(x) cerr << #x << " is " << x << endl;
#define ok cerr << "ok" << endl;
#define endl '\n'
#define int long long
#define ld long double

const int N = 5e5 + 5;

vector<int> g[N];

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 0, x, y; i < n - 1; ++i)
	{
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	vector<int> leaves;
	for (int i = 0; i < n; ++i)
		if (g[i].size() == 1)
			leaves.push_back(i + 1);

	vector<pt> ans;
	for (int i = 0; i + 2 < leaves.size(); i += 2)
		ans.push_back({leaves[i], leaves[i + 1]});

	if (leaves.size() % 2)
		ans.push_back({leaves[0], leaves.back()});

	cout << ans.size() << endl;
	for (auto i: ans)
		cout << i.x << " " << i.y << endl;

	return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:40:24: 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]
   40 |  for (int i = 0; i + 2 < leaves.size(); i += 2)
      |                  ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12140 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12140 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12140 KB Invalid number of links.
2 Halted 0 ms 0 KB -