# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666558 | 2022-11-29T03:01:45 Z | Kaztaev_Alisher | Hard route (IZhO17_road) | C++17 | 2000 ms | 724 KB |
//#pragma GCC optomize ("Ofast") //#pragma GCC optomize ("unroll-loops") //#pragma GCC target ("avx,avx2,fma") #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define sz size #define cl clear #define ins insert #define ers erase #define pii pair < int , int > #define pll pair< long long , long long > #define all(x) x.begin() , x.end() #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define tostr(x) to_string(x) #define tonum(s) atoi(s.c_str()) #define seon(x) setprecision(x) #define bpop(x) __builtin_popcount(x) #define deb(x) cerr << #x << " = " << x << endl; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; const double PI = 3.14159265; const ll N = 5e3+5; const ll mod = 1e9+7; const ll inf = 1e9; const ll INF = 1e18; using namespace std; int n , ok = 0 , cnt1 = 0 , cnt = 0 , kal = 0; vector<int> g[N] , vec; bool was[N]; void dfs(int v , int fn , int p){ was[v] = 1; cnt++; if(v == fn){ cnt1 = cnt; ok = 1; return; } for(int to : g[v]){ if(to==p) continue; dfs(to , fn , v); if(ok == 1) return; } if(ok == 1) return; cnt--; was[v] = 0; } void get(int v ,int p){ if(was[v] == 1){ ok = 1; return; } kal++; for(int to : g[v]){ if(to == p) continue; get(to,v); if(ok == 1) return; } kal--; } void solve(){ cin >> n; for(int i = 1; i < n; i++){ int a , b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } for(int i = 1; i <= n; i++){ if(g[i].sz() == 1) vec.pb(i); } int ans = 0 , ans2 = 0; for(int i = 0; i < vec.sz(); i++){ for(int j = i+1; j < vec.sz(); j++){ int mx = 0; ok = 0; cnt = 0; cnt1 = 0; dfs(vec[i] , vec[j] , 0); for(int k = 0; k < vec.sz(); k++){ if(i != k && j != k){ kal = 0; ok = 0; get(vec[k] , 0); mx = max(mx , kal); } } for(int k = 1; k <= n; k++) was[k] = 0; cnt1--; if(cnt1*mx > ans){ ans = cnt1*mx; ans2 = 1; } else if(cnt1*mx == ans) ans2++; } } cout << ans <<" " << ans2 <<"\n"; } signed main(){ file("road"); ios; solve(); return 0; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 448 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 10 ms | 444 KB | Output is correct |
12 | Correct | 10 ms | 340 KB | Output is correct |
13 | Correct | 9 ms | 456 KB | Output is correct |
14 | Correct | 9 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 448 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 5 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 448 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 10 ms | 444 KB | Output is correct |
12 | Correct | 10 ms | 340 KB | Output is correct |
13 | Correct | 9 ms | 456 KB | Output is correct |
14 | Correct | 9 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 448 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 5 ms | 340 KB | Output is correct |
25 | Execution timed out | 2024 ms | 724 KB | Time limit exceeded |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 448 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 440 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 10 ms | 444 KB | Output is correct |
12 | Correct | 10 ms | 340 KB | Output is correct |
13 | Correct | 9 ms | 456 KB | Output is correct |
14 | Correct | 9 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 440 KB | Output is correct |
18 | Correct | 1 ms | 448 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 5 ms | 340 KB | Output is correct |
25 | Execution timed out | 2024 ms | 724 KB | Time limit exceeded |
26 | Halted | 0 ms | 0 KB | - |