이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N],sum,t;
vector<int> v[N],ans;
void f(int ind,int back)
{
for(int i=0;i<v[ind].size();i++)
{
if(v[ind][i]!=back)
f(v[ind][i],ind);
}
if(v[ind].size()==1)
ans.pb(ind);
}
int main()
{
fast;
cin>>n;
int root=1;
fo(i,1,n-1)
{
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
if(v[a].size()!=1)
root=a;
if(v[b].size()!=1)
root=b;
}
f(root,root);
cout<<(ans.size()+1)/2<<endl;
for(int i=0;i<ans.size()/2;i++)
cout<<ans[i]<<sp<<ans[i+ans.size()/2]<<endl;
if(ans.size()%2==1)
cout<<ans[ans.size()-1]<<sp<<ans[0]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp: In function 'void f(int, int)':
net.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[ind].size();i++)
~^~~~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:56:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size()/2;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... |