이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define pi pair<ll,ll>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
const int N = 1e6 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n; vector<ll>g[N];
vector<ll>leaf; bool vis[N];
void dfs(ll u,ll p = 0){
if(g[u].size() == 1)leaf.push_back(u);
for(ll &v : g[u])
if(v != p) dfs(v,u);
}
void solve(){
cin>>n;
for(ll i = 1;i < n;++i){
ll u,v; cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
cout<<(leaf.size() + 1)/2<<endl;
for(ll i = 0;2*i < leaf.size();++i)
cout<<leaf[i]<<" "<<leaf[i + leaf.size()/2]<<endl;
}
signed main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
ll t = 1; //cin>>t;
while(t--) solve();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp: In function 'void solve()':
net.cpp:31:22: 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]
31 | for(ll i = 0;2*i < leaf.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... |