# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
764879 | vjudge1 | Network (BOI15_net) | C++17 | 2 ms | 2656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx","avx2","fma")
#pragma GCC Optimization("unroll-loops")
#pragma ("reroll")
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+9;
const long long inf=1e15;
const int mod=1e9+7;
vector<int>g[maxn];
bool used[maxn];
int in[maxn];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
// 24.06.2023
// Iseque
int n;
cin>>n;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
in[v]++;
g[v].push_back(u);
in[u]++;
}
int cnt=0;
vector<pair<int,int>>v;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(in[i]==1&&g[j].size()==1&&g[j][1]!=i&&i!=j) {
cnt++;
v.push_back({i,j});
g[j].push_back(i);
g[i].push_back(j);
in[i]++;
in[j]++;
}
}
}
cout<<cnt<<'\n';
for(int i=0;i<v.size();i++){
cout<<v[i].first<<' '<<v[i].second<<'\n';
}
return 0;
}
Compilation message (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... |