이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
#define EPS 0.00000001
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
vector<int>adj[500001];
bool vis[500001];
vector<int>leaves;
void dfs(int u=0){
vis[u]=1;
if(adj[u].size()==1)
leaves.push_back(u);
for(auto v:adj[u]){
if(!vis[v])
dfs(v);
}
}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
int n=nxt();
for(int i=0;i<n-1;i++){
int x=nxt()-1,y=nxt()-1;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs();
int leaf = leaves.size();
cout<<(leaf+1)/2<<endl;
for(int i=0;i<leaves.size();i+=2)
cout<<leaves[i]+1<<' '<<leaves[(i+1)%leaf]+1<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp:21:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
21 | const int mo=1e9+7,INF=1e18;
| ^~~~
net.cpp: In function 'int main()':
net.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<leaves.size();i+=2)
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |