Submission #113182

#TimeUsernameProblemLanguageResultExecution timeMemory
113182davitmargNetwork (BOI15_net)C++17
0 / 100
4 ms2688 KiB
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <ctype.h> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin (),v.end() using namespace std; int n; vector<int> g[100005],t; vector<pair<int, int>> ans; int main() { cin >> n; if (n == 0) { printf("0\n"); return 0; } for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); g[a].PB(b); g[b].PB(a); } for (int i = 1; i <= n; i++) if (g[i].size() == 1) t.PB(i); random_shuffle(all(t)); if (t.size() % 2) ans.PB(MP(t[t.size() - 2], t.back())); for (int i = 1; i < t.size(); i += 2) ans.PB(MP(t[i - 1], t[i])); printf("%d\n",(int)ans.size()); for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second); return 0; } /* */

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < t.size(); i += 2)
                  ~~^~~~~~~~~~
net.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++)
                  ~~^~~~~~~~~~~~
net.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...