Submission #1224957

#TimeUsernameProblemLanguageResultExecution timeMemory
1224957kokoxuyaNetwork (BOI15_net)C++20
0 / 100
6 ms12100 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define ss second #define ff first #define piii pair<int,pii> #define debu(x) (cerr << #x << " = "<< x << "\n") #define debu2(x,y) (cerr << #x << " = "<< x << " " << #y << " = " << y << "\n") #define debu3(x,y,z) (cerr << #x << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n") #define bitout(x,y) {\ cerr << #x << " : ";\ for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\ cout << "\n";\ } #define rangeout(j,rangestart,rangeend) {\ cerr << "outputting" << #j<< ":\n";\ for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\ cerr<<"\n";\ } #define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();} #define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();} #define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();} #define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();} #define defN 500001 vector<int>tbp; vector<vector<int>>adjlist(defN); vector<bool>visited(defN); void dfs(int cn) { visited[cn]=true; bool isleaf=true; for(int to:adjlist[cn]) { if(visited[to])continue; isleaf=false; dfs(to); } if(isleaf)tbp.pb(cn); } signed main() { int t1,t2,t3,t4; mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n;cin>>n; for(int a=1;a<n;a++) { cin>>t1>>t2; adjlist[t1].pb(t2); adjlist[t2].pb(t1); } dfs(1); int root=1; if(tbp.size()>=2){root=tbp[0];tbp.erase(tbp.begin());} cout<<tbp.size()<<"\n"; for(int x:tbp) { cout<<x<<" "<<root<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...