# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
37726 |
2017-12-27T10:17:50 Z |
Kerim |
Hard route (IZhO17_road) |
C++14 |
|
569 ms |
5536 KB |
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<int>adj[MAXN];
int ans,cnt,dp[MAXN],dp2[MAXN];
void precalc(int nd,int pr){
dp[nd]=dp2[nd]=0;
for(int i=0;i<int(adj[nd].size());i++){
int to=adj[nd][i];
if(to==pr)
continue;
precalc(to,nd);
if(dp[nd]<dp[to]+1){
dp2[nd]=dp[nd];
dp[nd]=dp[to]+1;
}
else if(dp2[nd]<dp[to]+1)
dp2[nd]=dp[to]+1;
}
}
void dfs(int nd,int pr,int dis,int mx){
if(~pr and (int)adj[nd].size()==1){
if(dis*mx>ans){
ans=dis*mx;
cnt=1;
}
else if(dis*mx==ans)
cnt++;
return;
}
for(int i=0;i<int(adj[nd].size());i++){
int to=adj[nd][i];
if(to==pr)
continue;
if(dp[to]+1==dp[nd])
dfs(to,nd,dis+1,max(dp2[nd],mx));
else
dfs(to,nd,dis+1,max(dp[nd],mx));
}
}
int main(){
//~ freopen("file.in", "r", stdin);
int n;
scanf("%d",&n);
if(n==2){
puts("0 1");
return 0;
}
for(int i=1;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
adj[u].pb(v);
adj[v].pb(u);
}
for(int i=1;i<=n;i++)
if(adj[i].size()==1){
precalc(i,-1);
dfs(i,-1,0,0);
}
printf("%d %d\n",ans,cnt/2);
return 0;
}
Compilation message
road.cpp: In function 'int main()':
road.cpp:60:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
road.cpp:67:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5140 KB |
Output is correct |
2 |
Correct |
0 ms |
5140 KB |
Output is correct |
3 |
Correct |
0 ms |
5140 KB |
Output is correct |
4 |
Correct |
0 ms |
5140 KB |
Output is correct |
5 |
Correct |
0 ms |
5140 KB |
Output is correct |
6 |
Correct |
0 ms |
5140 KB |
Output is correct |
7 |
Correct |
0 ms |
5140 KB |
Output is correct |
8 |
Correct |
0 ms |
5140 KB |
Output is correct |
9 |
Correct |
0 ms |
5140 KB |
Output is correct |
10 |
Correct |
0 ms |
5140 KB |
Output is correct |
11 |
Correct |
0 ms |
5140 KB |
Output is correct |
12 |
Correct |
0 ms |
5140 KB |
Output is correct |
13 |
Correct |
0 ms |
5140 KB |
Output is correct |
14 |
Correct |
0 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
5140 KB |
Output is correct |
16 |
Correct |
0 ms |
5140 KB |
Output is correct |
17 |
Correct |
0 ms |
5140 KB |
Output is correct |
18 |
Correct |
0 ms |
5140 KB |
Output is correct |
19 |
Correct |
0 ms |
5140 KB |
Output is correct |
20 |
Correct |
0 ms |
5140 KB |
Output is correct |
21 |
Correct |
0 ms |
5140 KB |
Output is correct |
22 |
Correct |
0 ms |
5140 KB |
Output is correct |
23 |
Correct |
0 ms |
5140 KB |
Output is correct |
24 |
Correct |
0 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5140 KB |
Output is correct |
2 |
Correct |
0 ms |
5140 KB |
Output is correct |
3 |
Correct |
0 ms |
5140 KB |
Output is correct |
4 |
Correct |
0 ms |
5140 KB |
Output is correct |
5 |
Correct |
0 ms |
5140 KB |
Output is correct |
6 |
Correct |
0 ms |
5140 KB |
Output is correct |
7 |
Correct |
0 ms |
5140 KB |
Output is correct |
8 |
Correct |
0 ms |
5140 KB |
Output is correct |
9 |
Correct |
0 ms |
5140 KB |
Output is correct |
10 |
Correct |
0 ms |
5140 KB |
Output is correct |
11 |
Correct |
0 ms |
5140 KB |
Output is correct |
12 |
Correct |
0 ms |
5140 KB |
Output is correct |
13 |
Correct |
0 ms |
5140 KB |
Output is correct |
14 |
Correct |
0 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
5140 KB |
Output is correct |
16 |
Correct |
0 ms |
5140 KB |
Output is correct |
17 |
Correct |
0 ms |
5140 KB |
Output is correct |
18 |
Correct |
0 ms |
5140 KB |
Output is correct |
19 |
Correct |
0 ms |
5140 KB |
Output is correct |
20 |
Correct |
0 ms |
5140 KB |
Output is correct |
21 |
Correct |
0 ms |
5140 KB |
Output is correct |
22 |
Correct |
0 ms |
5140 KB |
Output is correct |
23 |
Correct |
0 ms |
5140 KB |
Output is correct |
24 |
Correct |
0 ms |
5140 KB |
Output is correct |
25 |
Correct |
356 ms |
5348 KB |
Output is correct |
26 |
Correct |
406 ms |
5340 KB |
Output is correct |
27 |
Correct |
379 ms |
5344 KB |
Output is correct |
28 |
Correct |
353 ms |
5344 KB |
Output is correct |
29 |
Correct |
503 ms |
5340 KB |
Output is correct |
30 |
Correct |
479 ms |
5344 KB |
Output is correct |
31 |
Correct |
513 ms |
5340 KB |
Output is correct |
32 |
Correct |
486 ms |
5340 KB |
Output is correct |
33 |
Correct |
3 ms |
5440 KB |
Output is correct |
34 |
Correct |
6 ms |
5440 KB |
Output is correct |
35 |
Correct |
3 ms |
5440 KB |
Output is correct |
36 |
Correct |
9 ms |
5444 KB |
Output is correct |
37 |
Correct |
0 ms |
5536 KB |
Output is correct |
38 |
Correct |
3 ms |
5536 KB |
Output is correct |
39 |
Correct |
6 ms |
5300 KB |
Output is correct |
40 |
Correct |
6 ms |
5272 KB |
Output is correct |
41 |
Correct |
9 ms |
5272 KB |
Output is correct |
42 |
Correct |
49 ms |
5272 KB |
Output is correct |
43 |
Correct |
43 ms |
5272 KB |
Output is correct |
44 |
Correct |
73 ms |
5272 KB |
Output is correct |
45 |
Correct |
166 ms |
5272 KB |
Output is correct |
46 |
Correct |
203 ms |
5272 KB |
Output is correct |
47 |
Correct |
449 ms |
5272 KB |
Output is correct |
48 |
Correct |
569 ms |
5404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5140 KB |
Output is correct |
2 |
Correct |
0 ms |
5140 KB |
Output is correct |
3 |
Correct |
0 ms |
5140 KB |
Output is correct |
4 |
Correct |
0 ms |
5140 KB |
Output is correct |
5 |
Correct |
0 ms |
5140 KB |
Output is correct |
6 |
Correct |
0 ms |
5140 KB |
Output is correct |
7 |
Correct |
0 ms |
5140 KB |
Output is correct |
8 |
Correct |
0 ms |
5140 KB |
Output is correct |
9 |
Correct |
0 ms |
5140 KB |
Output is correct |
10 |
Correct |
0 ms |
5140 KB |
Output is correct |
11 |
Correct |
0 ms |
5140 KB |
Output is correct |
12 |
Correct |
0 ms |
5140 KB |
Output is correct |
13 |
Correct |
0 ms |
5140 KB |
Output is correct |
14 |
Correct |
0 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
5140 KB |
Output is correct |
16 |
Correct |
0 ms |
5140 KB |
Output is correct |
17 |
Correct |
0 ms |
5140 KB |
Output is correct |
18 |
Correct |
0 ms |
5140 KB |
Output is correct |
19 |
Correct |
0 ms |
5140 KB |
Output is correct |
20 |
Correct |
0 ms |
5140 KB |
Output is correct |
21 |
Correct |
0 ms |
5140 KB |
Output is correct |
22 |
Correct |
0 ms |
5140 KB |
Output is correct |
23 |
Correct |
0 ms |
5140 KB |
Output is correct |
24 |
Correct |
0 ms |
5140 KB |
Output is correct |
25 |
Correct |
356 ms |
5348 KB |
Output is correct |
26 |
Correct |
406 ms |
5340 KB |
Output is correct |
27 |
Correct |
379 ms |
5344 KB |
Output is correct |
28 |
Correct |
353 ms |
5344 KB |
Output is correct |
29 |
Correct |
503 ms |
5340 KB |
Output is correct |
30 |
Correct |
479 ms |
5344 KB |
Output is correct |
31 |
Correct |
513 ms |
5340 KB |
Output is correct |
32 |
Correct |
486 ms |
5340 KB |
Output is correct |
33 |
Correct |
3 ms |
5440 KB |
Output is correct |
34 |
Correct |
6 ms |
5440 KB |
Output is correct |
35 |
Correct |
3 ms |
5440 KB |
Output is correct |
36 |
Correct |
9 ms |
5444 KB |
Output is correct |
37 |
Correct |
0 ms |
5536 KB |
Output is correct |
38 |
Correct |
3 ms |
5536 KB |
Output is correct |
39 |
Correct |
6 ms |
5300 KB |
Output is correct |
40 |
Correct |
6 ms |
5272 KB |
Output is correct |
41 |
Correct |
9 ms |
5272 KB |
Output is correct |
42 |
Correct |
49 ms |
5272 KB |
Output is correct |
43 |
Correct |
43 ms |
5272 KB |
Output is correct |
44 |
Correct |
73 ms |
5272 KB |
Output is correct |
45 |
Correct |
166 ms |
5272 KB |
Output is correct |
46 |
Correct |
203 ms |
5272 KB |
Output is correct |
47 |
Correct |
449 ms |
5272 KB |
Output is correct |
48 |
Correct |
569 ms |
5404 KB |
Output is correct |
49 |
Runtime error |
0 ms |
5140 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |