省略
省略
C++に変換後のコードはこちら
int N, F, T, X;
int res[2d5];
int under[2d5], top[2d5], bottom[2d5];
int solve(int n){
if(res[n] >= 0) return res[n];
return res[n] = solve(under[n]);
}
{
int tmp;
rd(N);
rep(i,N) res[i] = under[i] = -1;
rep(i,N) top[i] = bottom[i] = i;
REP(rd_int()){
rd(F--, T--, X--);
tmp = top[F];
top[F] = under[X];
if(bottom[F] == X) bottom[F] = -1;
under[X] = top[T];
top[T] = tmp;
if(bottom[T]==-1) bottom[T] = X;
}
rep(i,N) if(bottom[i] != -1) res[bottom[i]] = i;
rep(i,N) solve(i);
wtLn(res(N)+1);
}
Current time: 2024年04月26日11時51分19秒
Last modified: 2021年01月02日17時05分24秒 (by laycrs)
Tags: Competitive_Programming_Incomplete AtCoder
トップページに戻る
Logged in as: unknown user (not login)