이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N=5e5+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
ll n;
vector<ll>adj[N], leaf, nonleaf;
void dfs(ll u, ll p)
{
if(adj[u].size()==1)
leaf.pb(u);
else
nonleaf.pb(u);
for(auto v:adj[u])
if(v!=p)
dfs(v, u);
}
int main()
{
inlld(n);
for(ll a=1; a<n; a++)
{
ll u, v;
inlld2(u, v);
adj[u].pb(v);
adj[v].pb(u);
}
for(ll a=1; a<=n; a++)
if(adj[a].size()>1)
{
dfs(a, 0);
break;
}
ll ans=((int)leaf.size()+1)/2;
printf("%lld\n", ans);
for(ll a=0; a*2+1<leaf.size(); a++)
printf("%lld %lld\n", leaf[a], leaf[a+(leaf.size()+1)/2]);
if(leaf.size()%2==1)
printf("%lld %lld\n", leaf[leaf.size()/2], leaf[0]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp: In function 'int main()':
net.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll a=0; a*2+1<leaf.size(); a++)
~~~~~^~~~~~~~~~~~
net.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld(a) scanf("%lld", &a)
~~~~~^~~~~~~~~~~~
net.cpp:36:5: note: in expansion of macro 'inlld'
inlld(n);
^~~~~
net.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
~~~~~^~~~~~~~~~~~~~~~~~~~
net.cpp:40:9: note: in expansion of macro 'inlld2'
inlld2(u, v);
^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |