제출 #1299388

#제출 시각아이디문제언어결과실행 시간메모리
1299388floVillage (BOI20_village)C++20
12 / 100
28 ms12100 KiB
#include <bits/stdc++.h> #define task "testing" #define ll long long #define multitest 0 using namespace std; const int N = 1e5; const ll inf = 1e18; int n; vector<int> adj[N+5]; namespace sub1 { const int sN = 10; int ds[sN+5][sN+5], id[N+5], ans[2][N+5]; bool check() { return n <= sN; } void dfs(int st, int v, int par) { for (auto u : adj[v]) { if (u == par) continue; ds[st][u] = ds[st][v]+1; dfs(st, u, v); } } void solve() { for (int x = 1; x <= n; x++) dfs(x, x, x); ll mn = inf, mx = -inf; for (int x = 1; x <= n; x++) id[x] = x; do { ll cur = 0; for (int x = 1; x <= n; x++) { if (x == id[x]) { cur = -1; break; } cur += ds[x][id[x]]; } if (cur == -1) continue; if (cur < mn) { mn = cur; for (int x = 1; x <= n; x++) { ans[0][x] = id[x]; } } if (cur > mx) { mx = cur; for (int x = 1; x <= n; x++) { ans[1][x] = id[x]; } } } while (next_permutation(id+1, id+n+1)); cout << mn << " " << mx << "\n"; for (int tp = 0; tp < 2; tp++) { for (int x = 1; x <= n; x++) { cout << ans[tp][x] << " "; } cout << "\n"; } } } void flo(int ID) { cin >> n; for (int x = 1; x < n; x++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if (sub1::check()) sub1::solve(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int TCS = 1, ID = 1; if (multitest) { cin >> TCS; } while (TCS--) flo(ID++); return 0; }

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

Village.cpp: In function 'int main()':
Village.cpp:103:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Village.cpp:104:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...