제출 #785478

#제출 시각아이디문제언어결과실행 시간메모리
785478RecursiveCoBosses (BOI16_bosses)C++14
22 / 100
1 ms324 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 vector<vector<int>> adjList; int solve(int v) { // What is the minimum possible sum of salaries (n + sum of heights) if we root the tree at v? int n = adjList.size(); int ans = n; vector<bool> visited(n, false); vector<int> dist(n, 1e18); queue<pair<int, int>> bfs; bfs.push({0, v}); while (!bfs.empty()) { auto top = bfs.front(); int distance = top.first; int node = top.second; bfs.pop(); if (visited[node]) continue; dist[node] = min(dist[node], distance); visited[node] = true; for (int con: adjList[node]) { if (!visited[con]) bfs.push({dist[node] + 1, con}); } } forto(n, i) ans += dist[i]; return ans; } signed main() { improvePerformance; //getTest; //eachTest { get(n); adjList.resize(n); forto(n, i) { get(cnt); forto(cnt, j) { get(v); v--; adjList[v].push_back(i); } } int ans = 1e18; forto(n, i) { ans = min(ans, solve(i)); } out(ans); //} }

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

bosses.cpp: In function 'long long int solve(long long int)':
bosses.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
bosses.cpp:42:5: note: in expansion of macro 'forto'
   42 |     forto(n, i) ans += dist[i];
      |     ^~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
bosses.cpp:51:9: note: in expansion of macro 'get'
   51 |         get(n);
      |         ^~~
bosses.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
bosses.cpp:53:9: note: in expansion of macro 'forto'
   53 |         forto(n, i) {
      |         ^~~~~
bosses.cpp:10:23: warning: unnecessary parentheses in declaration of 'cnt' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
bosses.cpp:54:13: note: in expansion of macro 'get'
   54 |             get(cnt);
      |             ^~~
bosses.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
bosses.cpp:55:13: note: in expansion of macro 'forto'
   55 |             forto(cnt, j) {
      |             ^~~~~
bosses.cpp:10:23: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
bosses.cpp:56:17: note: in expansion of macro 'get'
   56 |                 get(v);
      |                 ^~~
bosses.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
bosses.cpp:62:9: note: in expansion of macro 'forto'
   62 |         forto(n, i) {
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...