Submission #765423

# Submission time Handle Problem Language Result Execution time Memory
765423 2023-06-24T12:43:47 Z vjudge1 Network (BOI15_net) C++17
0 / 100
6 ms 12068 KB
#include <bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define mps make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define sz(x) (x).size() 
#define all(x) (x).begin(), (x).end()
#define booster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fopen(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
 
using namespace std;

const int N = 5e5 + 123;

vector <int> g[N],vec;

bool used[N];

void dfs(int v){
	used[v] = true;

	if(sz(g[v]) == 1){
		vec.pb(v);
	}

	for(auto i : g[v]){
		if(!used[i]){
			dfs(i);
		}
	}
}

signed main()
{ 
	booster	

	int n;
	cin >> n;

	for(int i = 1; i <= n - 1; i++){
		int x,y;
		cin >> x >> y;

		g[x].pb(y);	
		g[y].pb(x);
	}

	int k = 0;

	for(int i = 1; i <= n; i++){
		if(sz(g[i]) != 1){
			dfs(i);
			break;
		}
	}

	vector <pair<int,int>> vec2;
	
	for(int i = 0; i < sz(vec) / 2; i++){
		vec2.pb(mps(vec[i], vec[i + sz(vec) / 2]));
	}
	
	if(sz(vec) % 2 == 1){
		vec2.pb(mps(vec[0], vec[sz(vec) / 2]));
	}

	cout << sz(vec2) << '\n';

	for(auto i : vec2){
		cout << i.F << ' ' << i.S << '\n';
	}

	return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:62: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]
   62 |  for(int i = 0; i < sz(vec) / 2; i++){
      |                 ~~^~~~~~~~~~~~~
net.cpp:51:6: warning: unused variable 'k' [-Wunused-variable]
   51 |  int k = 0;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Incorrect 5 ms 12068 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Incorrect 5 ms 12068 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Incorrect 5 ms 12068 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -