제출 #543435

#제출 시각아이디문제언어결과실행 시간메모리
543435OlympiaNetwork (BOI15_net)C++17
100 / 100
405 ms40980 KiB
#include <vector> #include <algorithm> #include <iostream> #include <set> #include <cmath> #include <map> #include <random> #include <cassert> #include <ctime> #include <cstdlib> #include <queue> #include <limits.h> using namespace std; vector<vector<int>> adj; vector<int> nodes; int root; void dfs (int curNode, int prevNode) { if (adj[curNode].size() == 1) nodes.push_back(curNode); for (int i: adj[curNode]) { if (i != prevNode) { dfs (i, curNode); } } } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; adj.resize(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v), adj[v].push_back(u); } for (int i = 0; i < n; i++) { if (adj[i].size() != 1) { root = i; } } dfs (0, 0); cout << (nodes.size() + 1)/2 << '\n'; for (int i = 0; i < (nodes.size() + 1)/2; i++) { cout << nodes[i] + 1 << " " << nodes[i + nodes.size()/2] + 1 << '\n'; } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < (nodes.size() + 1)/2; i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...