萌新求助
查看原帖
萌新求助
125322
bessie_goes_moo楼主2021/12/17 20:02

把空间开大,或者在第51行(*)处写j+1可过

#include<bits/stdc++.h>
using namespace std;
struct IO{
    static const int S=1<<21;
    char buf[S],*p1,*p2;int st[105],Top;
    ~IO(){clear();}
    inline void clear(){fwrite(buf,1,Top,stdout);Top=0;}
    inline void pc(const char c){Top==S&&(clear(),0);buf[Top++]=c;}
    inline char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
    inline IO&operator >> (char&x){while(x=gc(),x==' '||x=='\n'||x=='\r');return *this;}
    template<typename T>inline IO&operator >> (T&x){
        x=0;bool f=0;char ch=gc();
        while(ch<'0'||ch>'9'){if(ch=='-') f^=1;ch=gc();}
        while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=gc();
        f?x=-x:0;return *this;
    }
    inline IO&operator << (const char c){pc(c);return *this;}
    template<typename T>inline IO&operator << (T x){
        if(x<0) pc('-'),x=-x;
        do{st[++st[0]]=x%10,x/=10;}while(x);
        while(st[0]) pc('0'+st[st[0]--]);return *this;
    }
}fin,fout;
const int N=2e5+5;
#define mp make_pair
typedef pair<int,int> PI;
map<PI,int>H;
int n,son[N*2],lnk[N],nxt[N*2],tot,f[N][2],p[N][3],ans;bool vis[N];
void add_e(int x,int y){
	son[++tot]=y,nxt[tot]=lnk[x],lnk[x]=tot;
}
#define v son[j]
void dfs(int x){
	vis[x]=1;
	for(int j=lnk[x];j;j=nxt[j]) if(!vis[v]){
		dfs(v);
		if(f[v][0]+1>f[x][0]) f[x][1]=f[x][0],f[x][0]=f[v][0]+1;
		else if(f[v][0]+1>f[x][1]) f[x][1]=f[v][0]+1;
	}
	ans=max(ans,f[x][0]+f[x][1]);
}
int main(){
	fin>>n;
	for(int i=1;i<=n-2;i++){
		for(int j=0;j<3;j++) fin>>p[i][j];
		sort(p[i],p[i]+3);
		for(int j=0;j<3;j++)
		for(int k=0/**/;k<3;k++) if(j^k){
			int&x=H[make_pair(p[i][j],p[i][k])];
			if(x&&x!=i) add_e(x,i),add_e(i,x);
			else x=i;
		}
	}
	dfs(1);printf("%d\n",ans+1);
	return 0;
}

2021/12/17 20:02
加载中...