Submission #134329

#TimeUsernameProblemLanguageResultExecution timeMemory
134329KastandaNetwork (BOI15_net)C++11
100 / 100
611 ms57800 KiB
// ItnoE #include<bits/stdc++.h> using namespace std; const int N = 500005; int n; vector < int > V, Adj[N]; void DFS(int v, int p) { for (int &u : Adj[v]) if (u != p) DFS(u, v); if (Adj[v].size() == 1) V.push_back(v); } int main() { scanf("%d", &n); for (int i = 1; i < n; i ++) { int v, u; scanf("%d%d", &v, &u); Adj[v].push_back(u); Adj[u].push_back(v); } int root = 1; for (int i = 1; i <= n; i ++) if (Adj[i].size() > 1) root = i; DFS(root, 0); printf("%d\n", (int)(V.size() + 1) / 2); for (int i = 0; i < (V.size() + 1) / 2; i ++) printf("%d %d\n", V[i], V[i + (int)V.size() / 2]); return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < (V.size() + 1) / 2; i ++)
                     ~~^~~~~~~~~~~~~~~~~~~~
net.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
net.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...