Compile Error
foo.cc:6:2: error: stray '#' in program
6 | }#include<bits/stdc++.h>
| ^
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:11: error: 'bits' was not declared in this scope
6 | }#include<bits/stdc++.h>
| ^~~~
foo.cc:6:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
6 | }#include<bits/stdc++.h>
| ^~~~
| std
foo.cc:6:3: error: 'include' does not name a type
6 | }#include<bits/stdc++.h>
| ^~~~~~~
foo.cc:10:1: error: 'vector' does not name a type
10 | vector<int>edge[M];
| ^~~~~~
foo.cc: In function 'void dfs1(int, int)':
foo.cc:17:16: error: 'edge' was not declared in this scope
17 | for(auto u:edge[x]){
| ^~~~
foo.cc:21:23: error: 'max' was not declared in this scope
21 | cur_level=max(cur_level,lv[x]);
| ^~~
foo.cc: In function 'void dfs(int, int)':
foo.cc:53:16: error: 'edge' was not declared in this scope
53 | for(auto u:edge[x]){
| ^~~~
foo.cc:58:14: error: 'max' was not declared in this scope
58 | level[p]=max(level[p],level[x]+1);
| ^~~
foo.cc:61:9: error: 'vector' was not declared in this scope
61 | vector<int>v;
| ^~~~~~
foo.cc:61:16: error: expected primary-expression before 'int'
61 | vector<int>v;
| ^~~
foo.cc:62:9: error: 'v' was not declared in this scope
62 | v.push_back(dp[p][0]);
| ^
foo.cc:65:9: error: 'sort' was not declared in this scope; did you mean 'short'?
65 | sort(v.rbegin(),v.rend());
| ^~~~
| short
foo.cc: At global scope:
foo.cc:70:5: error: redefinition of 'int main()'
70 | int main()
| ^~~~
foo.cc:3:5: note: 'int main()' previously defined here
3 | int main()
| ^~~~
foo.cc: In function 'int main()':
foo.cc:72:5: error: 'ios' has not been declared
72 | ios::sync_with_stdio(false);
| ^~~
foo.cc:73:5: error: 'cin' was not declared in this scope
73 | cin.tie(0);
| ^~~
foo.cc:82:9: error: 'edge' was not declared in this scope
82 | edge[u].push_back(v);
| ^~~~
foo.cc:90:6: error: 'cout' was not declared in this scope
90 | cout<<target_distane<<" "<<ans<<"\n";
| ^~~~
Code
#include <stdio.h>
int main()
{
printf("hello, world\n");
}#include<bits/stdc++.h>
using namespace std;
const long long M=3e5+10,MOD=1000000007;
typedef long long ll;
vector<int>edge[M];
int level[M];
int lv[M];
int ans=1;
int target_distane=0;// using method re-rooting dp
int dp[M][2];
void dfs1(int x,int p){
for(auto u:edge[x]){
if(u!=p){
int cur_level=dp[x][0];
if(dp[x][0]==level[u]+1)cur_level=dp[x][1];
cur_level=max(cur_level,lv[x]);
int total=cur_level+level[u];
total/=2;
lv[u]=cur_level+1;// root to down length
if(total>=target_distane){
if(total==target_distane){
if(cur_level==level[u])ans=max(ans,max(u,x));
else{
int dif=cur_level-level[u];
if(dif==1)ans=max(ans,x);
if(dif==-1)ans=max(ans,u);
}
}
else{
if(cur_level==level[u]){
ans=max(u,x);
target_distane=total;
}
else{
int dif=cur_level-level[u];
if(dif==1)ans=x,target_distane=total;
if(dif==-1)ans=u,target_distane=total;
}
}
}
dfs1(u,x);
}
}
}
void dfs(int x,int p){
dp[x][1]=dp[x][0]=1;
for(auto u:edge[x]){
if(u!=p){
dfs(u,x);
}
}
level[p]=max(level[p],level[x]+1);
if(p!=0){
int cur=level[x]+1;
vector<int>v;
v.push_back(dp[p][0]);
v.push_back(dp[p][1]);
v.push_back(cur);
sort(v.rbegin(),v.rend());
dp[p][0]=v[0];// first max
dp[p][1]=v[1];//second max
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
edge[u].push_back(v);
edge[v].push_back(u);
}
for(int i=1;i<=n;i++){
level[i]=1;
}
dfs(1,0);// lower level and upper level length
dfs1(1,0);
cout<<target_distane<<" "<<ans<<"\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1069 H. Vaccination
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-07-12 16:57:02
- Judged At
- 2024-12-17 11:29:04
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes