Compile Error
/in/foo.cc:6:57: error: 'int time' redeclared as different kind of symbol int size[maxn],top[maxn],son[maxn],tin[maxn],tout[maxn],time,fat[maxn],dep[maxn],que[maxn],q; ^~~~ In file included from /usr/include/pthread.h:24:0, from /usr/include/x86_64-linux-gnu/c++/7/bits/gthr-default.h:35, from /usr/include/x86_64-linux-gnu/c++/7/bits/gthr.h:148, from /usr/include/c++/7/ext/atomicity.h:35, from /usr/include/c++/7/bits/ios_base.h:39, from /usr/include/c++/7/ios:42, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from /in/foo.cc:2: /usr/include/time.h:192:15: note: previous declaration 'time_t time(time_t*)' extern time_t time (time_t *__timer) __THROW; ^~~~ /in/foo.cc: In function 'void inc(int, int)': /in/foo.cc:9:45: warning: pointer to a function used in arithmetic [-Wpointer-arith] inline void inc(int x,int a){while(x<=(time)+5){c[x]+=a;x+=lowbit(x);}} ~~~~~~^~ /in/foo.cc:9:46: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] inline void inc(int x,int a){while(x<=(time)+5){c[x]+=a;x+=lowbit(x);}} ^ /in/foo.cc: In function 'void dfs(int, int)': /in/foo.cc:15:16: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) throw () {aka long int (*)(long int*) throw ()}' [-Wpointer-arith] tin[a] = ++time; ^~~~ /in/foo.cc:15:16: error: lvalue required as increment operand /in/foo.cc:27:18: warning: pointer to a function used in arithmetic [-Wpointer-arith] tout[a]= time+1; ~~~~^~ /in/foo.cc:27:18: error: invalid conversion from 'time_t (*)(time_t*) throw () {aka long int (*)(long int*) throw ()}' to 'int' [-fpermissive] /in/foo.cc: In function 'int main()': /in/foo.cc:63:9: warning: unused variable 's' [-Wunused-variable] int s = 1; ^
代码
#include <stdio.h>
#include <iostream>
using namespace std;
const int maxn = 3e5+4;
int c[maxn+5],n,m;
int size[maxn],top[maxn],son[maxn],tin[maxn],tout[maxn],time,fat[maxn],dep[maxn],que[maxn],q;
inline int lowbit(int x){return x&(-x);}
inline int sum(int x){int ret = 0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
inline void inc(int x,int a){while(x<=(time)+5){c[x]+=a;x+=lowbit(x);}}
int head[maxn],nex[maxn*2],dist[maxn*2],qq;
inline void connect(int a,int b){nex[++qq] = head[a];dist[qq] = b;head[a] = qq;nex[++qq] = head[b];dist[qq] = a;head[b] = qq;}
void dfs(int a,int fa){
dep[a] = dep[fa]+1;
fat[a] = fa;
tin[a] = ++time;
son[a] = -1;
for(int i = head[a];i;i=nex[i]){
int to = dist[i];
if(to!=fa){
dfs(to,a);
size[a]+=size[to];
if(son[a]==-1||size[to]>size[son[a]]){
son[a] = to;
}
}
}
tout[a]= time+1;
}
void dfs2(int a,int t){
top[a] = t;
if(son[a]==-1) return;
dfs2(son[a],t);
for(int i = head[a];i;i=nex[i]){
int to = dist[i];
if(to!=fat[a]&&to!=son[a]){
dfs2(to,to);
}
}
}
int lca(int x,int y){
while(top[x]!=top[y]){
if(dep[top[x]]>dep[top[y]])
x = fat[top[x]];
else
y = fat[top[y]];
}
return dep[x]<dep[y]?x:y;
}
int read()
{
int x=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
int main(){
n = read(),m = read();
int s = 1;
for(int i = 1;i<=n-1;i++){
int x,y;x=read(),y=read();
connect(x,y);
}
dfs(n/2,n/2);
dfs2(n/2,n/2);
for(int i = 1;i<=m;i++){
char c;cin>>c;
if(c=='Q'){
int x=read(),y=read();
if(!(sum(tin[x])+sum(tin[y])-2*sum(tin[lca(x,y)]))){
puts("Yes");
}else{
puts("No");
}
}else if(c=='C'){
int x=read(),y=read();
if(dep[x]<dep[y]) x = y;
inc(tin[x],1);inc(tout[x],-1);
que[++q] = x;
}else{
int x=read();
inc(tin[que[x]],-1);
inc(tout[que[x]],1);
}
}
return 0;
}
信息
- 递交者
- 类型
- 递交
- 题目
- 部落冲突(数据加强)
- 题目数据
- 下载
- 语言
- C++
- 递交时间
- 2017-10-29 11:44:14
- 评测时间
- 2017-10-29 11:44:27
- 评测机
- 分数
- 0
- 总耗时
- 355ms
- 峰值内存
- 29.941 MiB