Submission #234429

#TimeUsernameProblemLanguageResultExecution timeMemory
234429bharat2002Network (BOI15_net)C++14
0 / 100
13 ms12160 KiB
/*input 8 1 2 2 3 3 4 4 5 3 6 3 7 3 8 */ #include<bits/stdc++.h> using namespace std; const int N=5e5 + 100; const int mod=1e9 + 7; #define int long long const int inf=1e18; #define pii pair<int, int> #define f first #define s second #define mp make_pair #define FOR(i, n) for(int i=1;i<=n;i++) #define TRACE(x) cerr << #x << " = " << x << endl //Trace prints the name of the variable and the value. int n;vector<int> adjlist[N];vector<int> nodes; signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n; for(int i=1;i<n;i++) { int a, b;cin>>a>>b;adjlist[a].push_back(b);adjlist[b].push_back(a); } for(int i=1;i<=n;i++) { if(adjlist[i].size()==1) nodes.push_back(i); } int ext=1; if(nodes.back()==ext) ext=n; int ans=nodes.size(); if(ans%2==1) ans++;ans/=2; cout<<ans<<endl; for(int i=0;i<nodes.size()-1;i+=2) { cout<<nodes[i]<<" "<<nodes[i+1]<<endl; } ans=nodes.size(); if(ans%2==1) cout<<ext<<" "<<nodes.back(); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:40:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(ans%2==1) ans++;ans/=2;
  ^~
net.cpp:40:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(ans%2==1) ans++;ans/=2;
                     ^~~
net.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<nodes.size()-1;i+=2)
              ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...