이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
void dfs(int v,int p,vvector<int> &G,vector<int> &lv) {
bool islv=true;
for (int i:G[v]) {
if (i==p) continue;
islv=false;
dfs(i,v,G,lv);
}
if (islv) lv.push_back(v);
}
int main() {
speed;
int n;
cin>>n;
vvector<int> G(n+1);
for (int i=0;i<n-1;i++) {
int a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
int rot=0;
for (int i=1;i<=n;i++) {
if (G[i].size()>1) {
rot=i;
break;
}
}
vector<int> lv;
dfs(rot,0,G,lv);
cout<<(lv.size()+1)/2<<"\n";
for (int i=0;i<lv.size()/2;i++) {
cout<<lv[2*i]<<" "<<lv[2*i+1]<<"\n";
}
if (lv.size()&1) cout<<lv[lv.size()-1]<<" "<<lv[lv.size()-2]<<"\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
net.cpp: In function 'int main()':
net.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i=0;i<lv.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... |