제출 #120012

#제출 시각아이디문제언어결과실행 시간메모리
120012E869120Network (BOI15_net)C++14
100 / 100
951 ms54892 KiB
#include <iostream> #include <vector> using namespace std; #pragma warning (disable: 4996) int N, A[1 << 19], B[1 << 19]; bool used[1 << 19]; vector<int> G[1 << 19], I; void dfs(int pos) { if (used[pos] == true) return; used[pos] = true; if (G[pos].size() == 1) I.push_back(pos); for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]); } int main() { scanf("%d", &N); for (int i = 1; i <= N - 1; i++) { scanf("%d%d", &A[i], &B[i]); G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); } int root = -1; for (int i = 1; i <= N; i++) { if (G[i].size() >= 2) root = i; } dfs(root); int mid = I.size() / 2; cout << I.size() - mid << endl; for (int i = 0; i < I.size() - mid; i++) cout << I[i] << " " << I[i + mid] << endl; return 0; }

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

net.cpp:4:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
net.cpp: In function 'void dfs(int)':
net.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
                  ~~^~~~~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < I.size() - mid; i++) cout << I[i] << " " << I[i + mid] << endl;
                  ~~^~~~~~~~~~~~~~~~
net.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
net.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...