답안 #639442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639442 2022-09-10T01:01:57 Z zordeno Network (BOI15_net) C++17
0 / 100
2 ms 4216 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; }

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);

	vector <ll> frq(MAX);
	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		ll u, v;
		cin >> u >> v;
		u--, v--;
		frq[u]++, frq[v]++;
	}
	ll sum = 0, prv;
	for (ll i = 0; i < n; i++)
	{
		if (frq[i] < 2)
		{
			sum++;
		}
	}
	cout << ceil(sum * 1.0 / 2.0) << endl;
	sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (frq[i] < 2)
		{
			sum++;
			if (sum % 2 == 0)
			{
				cout << prv + 1 << " " << i + 1 << endl;
			}
			prv = i;
		}
	}
	if (sum % 2 != 0)
	{
		for (ll i = n - 1; i >= 0; i--)
		{
			if (frq[i] < 2)
			{
				if (i == n - 1)
				{
					cout << i + 1 << " 1" << endl;
				}
				else
				{
					cout << i + 1 << " " << n << endl;
				}
				break;
			}
		}
	}
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:48:19: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     cout << prv + 1 << " " << i + 1 << endl;
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4216 KB Output is correct
4 Incorrect 2 ms 4180 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4216 KB Output is correct
4 Incorrect 2 ms 4180 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4216 KB Output is correct
4 Incorrect 2 ms 4180 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -