Submission #779412

#TimeUsernameProblemLanguageResultExecution timeMemory
779412vjudge1Village (BOI20_village)C++17
12 / 100
1069 ms1364 KiB
#include <iostream> #include <vector> #define INF 2000000000 #define MAX 1000 using namespace std; ///ifstream cin ("c.in"); ///ofstream cout ("c.out"); vector <int> graph[MAX + 10]; int dist[MAX + 10][MAX + 10], st[MAX + 10], visited[MAX + 10], n, source, minDist, maxDist, vmin[MAX + 10], vmax[MAX + 10]; void speedy() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void dfs(int node) { for (auto next : graph[node]) if (dist[source][next] == 0) { dist[source][next] = dist[source][node] + 1; dfs(next); } } void solution() { int ok = 1; for (int i = 1; i <= n && ok == 1; i++) if (st[i] == i) ok = 0; if (ok == 1) { int totalDist = 0; for (int i = 1; i <= n; i++) totalDist = totalDist + dist[i][st[i]]; if (totalDist < minDist) { minDist = totalDist; for (int i = 1; i <= n; i++) vmin[i] = st[i]; } if (totalDist > maxDist) { maxDist = totalDist; for (int i = 1; i <= n; i++) vmax[i] = st[i]; } } } void bkt(int k) { if (k == n + 1) solution(); else for (int i = 1; i <= n; i++) if (visited[i] == 0) { visited[i] = 1; st[k] = i; bkt(k + 1); visited[i] = 0; } } int main() { speedy(); cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; graph[x].push_back(y); graph[y].push_back(x); } for (int i = 1; i <= n; i++) { source = i; dist[source][source] = 1; dfs(i); for (int j = 1; j <= n; j++) dist[source][j]--; } minDist = INF; maxDist = 0; bkt(1); cout << minDist << ' ' << maxDist << '\n'; for (int i = 1; i <= n; i++) cout << vmin[i] << ' '; cout << '\n'; for (int i = 1; i <= n; i++) cout << vmax[i] << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...