제출 #810683

#제출 시각아이디문제언어결과실행 시간메모리
810683RecursiveCoNetwork (BOI15_net)C++14
100 / 100
445 ms108636 KiB
// CF template, version 3.0 #include <bits/stdc++.h> using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} #define int long long int vector<vector<int>> subleaves; vector<bool> visited; vector<bool> leaf; vector<vector<int>> adjList; void dfs(int v, int p) { visited[v] = true; if (p != -1 && leaf[v]) subleaves[p].push_back(v); for (int con: adjList[v]) { if (!visited[con]) { dfs(con, p == -1? con: p); } } } signed main() { improvePerformance; get(n); adjList.resize(n); forto(n - 1, i) { get(a); get(b); a--; b--; adjList[a].push_back(b); adjList[b].push_back(a); } leaf.resize(n, false); int leaves = 0; forto(n, i) { if (adjList[i].size() == 1) leaf[i] = true, leaves++; } // we choose to root the tree at some non-leaf int root = -1; forto(n, i) { if (adjList[i].size() != 1) { root = i; break; } } vector<pair<int, int>> edges; subleaves.resize(n); visited.resize(n, false); dfs(root, -1); vector<vector<int>> leafvecs; forto(n, i) { if (!subleaves[i].empty()) { leafvecs.push_back(subleaves[i]); } } vector<int> all; for (auto vec: leafvecs) { for (int node: vec) all.push_back(node); } forto(all.size() / 2, i) { edges.push_back({all[i], all[i + all.size() / 2]}); } if (all.size() % 2) { edges.push_back({all[0], all.back()}); } out(edges.size()); for (auto edge: edges) { out("\n"); out(edge.first + 1); out(" "); out(edge.second + 1); } }

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

net.cpp: In function 'int main()':
net.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
net.cpp:38:5: note: in expansion of macro 'get'
   38 |     get(n);
      |     ^~~
net.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
net.cpp:40:5: note: in expansion of macro 'forto'
   40 |     forto(n - 1, i) {
      |     ^~~~~
net.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
net.cpp:41:9: note: in expansion of macro 'get'
   41 |         get(a);
      |         ^~~
net.cpp:10:23: warning: unnecessary parentheses in declaration of 'b' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
net.cpp:42:9: note: in expansion of macro 'get'
   42 |         get(b);
      |         ^~~
net.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
net.cpp:50:5: note: in expansion of macro 'forto'
   50 |     forto(n, i) {
      |     ^~~~~
net.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
net.cpp:55:5: note: in expansion of macro 'forto'
   55 |     forto(n, i) {
      |     ^~~~~
net.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
net.cpp:66:5: note: in expansion of macro 'forto'
   66 |     forto(n, i) {
      |     ^~~~~
net.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
net.cpp:75:5: note: in expansion of macro 'forto'
   75 |     forto(all.size() / 2, i) {
      |     ^~~~~
net.cpp:15:52: 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]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                              ~~~~~~^~~~~~~~
net.cpp:75:5: note: in expansion of macro 'forto'
   75 |     forto(all.size() / 2, i) {
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...