QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84427 | #5651. Parmigiana With Seafood | johnsonloy_x | Compile Error | / | / | C++14 | 1.8kb | 2023-03-06 14:55:14 | 2023-03-06 14:55:14 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-03-06 14:55:14]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-03-06 14:55:14]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
const int maxn = 1e6+10;
namespace IO{
void openfile(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
}
int add(int x,int y){
x+=y;
if(x>=mod)
x-=mod;
return x;
}
int sub(int x,int y){
x-=y;
if(x<0)
x+=mod;
return x;
}
inline int read(){
int x = 0,f = 0;
char c = getchar();
while(!isdigit(c))
f|=c=='-',c = getchar();
while(isdigit(c))
x = x*10+c-'0',c = getchar();
if(f)x = -x;
return x;
}
}
int n,dep[maxn],ans,f[maxn][2];
set<int>q;
vector<int>e[maxn],d[2];
void dfs(int x,int fa){
dep[x] = dep[fa]+1;
for(auto v:e[x]){
if(v==fa)
continue;
dfs(v,x);
}
}
void dfs1(int x,int fa){
if(dep[x]&1){
auto y = q.lower_bound(x);
if(y!=q.begin())
y--;
if(y!=q.begin())
ans = max(ans,*y);
}
for(auto v:e[x]){
if(v==fa)continue;
dfs(v,x);
}
q.insert(x);
}
void dfs3(int x,int fa){
f[x][dep[x]&1] = x;
for(auto v:e[x]){
if(v==fa)continue;
dfs3(v,x);
f[x][0] = max(f[v][0],f[x][0]);
f[x][1] = max(f[x][1],f[v][1]);
}
}
signed main(){
openfile();
n = read();
for(int i=1;i<n;i++){
int x = read(),y = read();
e[x].push_back(y),e[y].push_back(x);
}
if(!(n&1)){
printf("%d\n",n);
return 0;
}
for(int i=1;i<=n;i++)
if(e[i].size()==1)
ans = max(ans,i);
dfs(n,0);
for(int i=1;i<=n;i++)
if(!(dep[i]&1))
ans = max(ans,i);
dfs1(n,0);
dfs2(n,0);
for(auto v:e[n]){
d[0].push_back(f[v][0]);
d[1].push_back(f[v][1]);
}
sort(d[0].begin(),d[0].end());
sort(d[1].begin(),d[1].end());
if(e[n].size()>=3)
ans = max(ans,max(d[0][e[n].size()-3],d[1][e[n].size()-3]));
printf("%d\n",ans);
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:81:9: error: ‘openfile’ was not declared in this scope; did you mean ‘IO::openfile’? 81 | openfile(); | ^~~~~~~~ | IO::openfile answer.code:9:14: note: ‘IO::openfile’ declared here 9 | void openfile(){ | ^~~~~~~~ answer.code:82:13: error: ‘read’ was not declared in this scope; did you mean ‘IO::read’? 82 | n = read(); | ^~~~ | IO::read answer.code:30:20: note: ‘IO::read’ declared here 30 | inline int read(){ | ^~~~ answer.code:85:32: error: ‘y’ was not declared in this scope 85 | e[x].push_back(y),e[y].push_back(x); | ^ answer.code:99:9: error: ‘dfs2’ was not declared in this scope; did you mean ‘dfs3’? 99 | dfs2(n,0); | ^~~~ | dfs3