제출 #633945

#제출 시각아이디문제언어결과실행 시간메모리
633945MinaRagy06Network (BOI15_net)C++17
0 / 100
7 ms12012 KiB
#include <bits/stdc++.h> using namespace std; #define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl '\n' #define int long long const int N = 5e5+5; vector<int> adj[N], leaf; void dfs(int i, int par) { if (adj[i].size() == 1) return leaf.push_back(i), void(); for (auto nxt : adj[i]) if (nxt != par) dfs(nxt, i); } signed main() { lesgooo; int n, u, v; cin >> n; for (int i =1 ; i < n; i++) cin >> u >> v, adj[--u].push_back(--v), adj[v].push_back(u); for (int i = 0; i < n; i++) if (adj[i].size() != 1) {dfs(i, -1); break;} cout << (leaf.size()+1)/2 << endl; for (int i = 0; i < leaf.size()/2; i++) cout << leaf[i]+1 << " " << leaf[leaf.size()/2+i]+1 << endl; if (leaf.size()&1) cout << leaf.back()+1 << " " << (leaf.back() == 0? 2 : 1) << endl; return 0; }

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

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