이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define F first
#define S second
#define nl '\n'
#define all(x) x.begin(), x.end()
const int N = 5e5 + 7;
const int modd = 1e9 + 7;
const int INF = 1e9 + 7;
const double pi = 3.141592653589793238462643383279502884197;
const double EPS = 0.0000000000001;
using namespace std;
int gcd(int a, int b){
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll binpow(ll a, ll x){
if(x == 0) return 1;
if(x % 2 == 0){
ll y = binpow(a, x / 2);
return (y * y);
}
else{
return (binpow(a, x - 1) * a);
}
}
ll n;
vector <ll> v[N];
vector <ll> s;
vector <ll> l;
vector <ll> r;
bool used[N];
void dfs(ll x){
used[x] = 1;
if(v[x].size() == 1){
s.pb(x);
}
for(auto to : v[x]){
if(used[to] == 0){
dfs(to);
}
}
}
void Muqaltin(){
cin >> n;
for(int i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].pb(y);
v[y].pb(x);
}
dfs(1);
for(int i = 0; i < s.size() / 2; i++){
l.pb(s[i]);
}
for(int i = s.size() / 2; i < s.size(); i++){
r.pb(s[i]);
}
cout << max(l.size(), r.size()) << nl;
for(int i = 0; i < min(l.size(), r.size()); i++){
cout << l[i] << ' ' << r[i] << nl;
}
if(l.size() > r.size()){
cout << l[l.size() - 1] << " " << l[0] << nl;
}
else if(l.size() < r.size()){
cout << r[r.size() - 1] << " " << r[0] << nl;
}
return;
}
int main(){
// freopen("pails.in", "r", stdin);
// freopen("pails.out", "w", stdout);
ios_base :: sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
Muqaltin();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp: In function 'void Muqaltin()':
net.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 0; i < s.size() / 2; i++){
| ~~^~~~~~~~~~~~~~
net.cpp:68:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = s.size() / 2; i < s.size(); i++){
| ~~^~~~~~~~~~
net.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
72 | for(int i = 0; i < min(l.size(), r.size()); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |