Submission #716597

#TimeUsernameProblemLanguageResultExecution timeMemory
716597Spade1Network (BOI15_net)C++14
0 / 100
1 ms324 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> //#include <grader.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX #define db double using namespace std; const int N = 5e5 + 10; int cnt[N]; void solve() { int n; cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; cnt[u]++, cnt[v]++; } vector<int> v; for (int i = 1; i <= n; ++i) if (cnt[i]==1) v.pb(i); cout << (v.size()+1)/2 << '\n'; for (int i = 0; i < v.size(); ++i) { if (i==v.size()-1) { cout << v[i] << " " << v[0] << '\n'; } else { cout << v[i] << " " << v[++i] << '\n'; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

Compilation message (stderr)

net.cpp: In function 'void solve()':
net.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
net.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (i==v.size()-1) {
      |             ~^~~~~~~~~~~~
net.cpp:33:38: warning: operation on 'i' may be undefined [-Wsequence-point]
   33 |             cout << v[i] << " " << v[++i] << '\n';
      |                                      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...