| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 47119 | MatheusLealV | Network (BOI15_net) | C++17 | 3 ms | 2828 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 100050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
int n, qtd, tempo;
vector<int> grafo[N];
vector<pii> leaf;
void dfs(int x, int p)
{
int ini = ++tempo;
for(auto v: grafo[x])
{
if(v == p) continue;
dfs(v, x);
}
if(grafo[x].size() == 1) leaf.push_back({tempo, x}), qtd ++;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1, a, b; i < n; i++)
{
cin>>a>>b;
grafo[a].push_back(b);
grafo[b].push_back(a);
}
dfs(1, 1);
sort(leaf.begin(), leaf.end());
cout<<(qtd + 1)/2<<"\n";
if( (qtd % 2 == 0) )
{
for(int i = 0; i < leaf.size()/2; i++)
cout<<leaf[i].s<<" "<<leaf[leaf.size() - i - 1].s<<'\n';
}
else
{
for(int i = 0; i < leaf.size()/2; i++)
cout<<leaf[i].s<<" "<<leaf[leaf.size() - i - 1].s<<'\n';
cout<<leaf[qtd/2].s<<" "<<leaf[0].s<<"\n";
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
