제출 #88019

#제출 시각아이디문제언어결과실행 시간메모리
88019inomHard route (IZhO17_road)C++14
19 / 100
2112 ms196964 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> #define fi first #define se second #define pb push_back #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define in freopen("road.in", "r", stdin); #define out freopen("road.out", "w", stdout); using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") #pragma warning(disable : 4996) typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 5005; const int INF = INT_MAX; const int MOD = 998244353; int TN = 1; int n; vector<int> leafs; vector<int> verr[N]; int d[N][N], parent[N][N]; int get(int x, int y) { set<int> path; multiset<int> mpath; // printf("%d %d %d\n", x, y, parent[x][y]); // printf("cities between %d & %d are: ", x, y); while (parent[x][y] != 0) { path.insert(y); mpath.insert(y); y = parent[x][y]; } path.insert(x); mpath.insert(x); if (sz(path) != sz(mpath)) { return -INF; } /*for (auto i: path) { printf("%d ", i); } puts("");*/ int cur_ans = 0; for (int i = 1; i <= n; i++) { if (path.find(i) == path.end()) { // printf("%d ", i); int cur = INF; for (auto j: path) { // printf("%d %d ", j, d[i][j]); cur = min(cur, d[i][j]); } // puts(""); cur_ans = max(cur_ans, cur); } } return cur_ans; } void solve() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, y; scanf("%d %d", &x, &y); verr[x].pb(y); verr[y].pb(x); } for (int i = 1; i <= n; i++) { if (sz(verr[i]) == 1) { leafs.pb(i); } } for (int i = 1; i <= n; i++) { queue<int> q; d[i][i] = 0; q.push(i); parent[i][i] = 0; while (!q.empty()) { int x = q.front(); q.pop(); for (auto to: verr[x]) { if (!d[i][to] && to != i) { d[i][to] = d[i][x] + 1; parent[i][to] = x; q.push(to); } } } } int ans = 0, cnt = 0; for (int i = 0; i < sz(leafs); i++) { for (int j = i + 1; j < sz(leafs); j++) { // puts(""); int len = d[leafs[i]][leafs[j]], H = get(leafs[i], leafs[j]); // printf("%d %d %d %d \n", leafs[i], leafs[j], len, H); // puts(""); len *= H; if (ans < len) { ans = len, cnt = 1; } else if (ans == len) { cnt++; } } } printf("%d %d", ans, cnt); return; } signed main() { // ios_base::sync_with_stdio(0); // in; out; // cin >> TN; while (TN--) { solve(); } return 0; }

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

road.cpp:22:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
 
road.cpp: In function 'void solve()':
road.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
road.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...