結果
| 問題 |
No.3193 Submit Your Solution
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2025-06-27 21:52:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,658 bytes |
| コンパイル時間 | 5,335 ms |
| コンパイル使用メモリ | 335,084 KB |
| 実行使用メモリ | 9,952 KB |
| 最終ジャッジ日時 | 2025-06-27 21:52:50 |
| 合計ジャッジ時間 | 19,012 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 16 |
ソースコード
/**
author: shobonvip
created: 2025.06.27 21:35:34
**/
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
typedef unsigned long long ull;
int f1[200001],f2[200001],g1[400001],g2[400001];
ull d1[200001],d2[200001],ans=0;
int mada[999999];
bool seen[999999];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<int> u(n-1), v(n-1), x(n-1), y(n-1);
vector ikeru1(n, vector<int>(0));
vector ikeru2(n, vector<int>(0));
rep(i,0,n-1) {
cin >> u[i] >> v[i];
u[i]--; v[i]--;
ikeru1[u[i]].push_back(v[i]);
ikeru1[v[i]].push_back(u[i]);
}
rep(i,0,n-1) {
cin >> x[i] >> y[i];
x[i]--; y[i]--;
ikeru2[x[i]].push_back(y[i]);
ikeru2[y[i]].push_back(x[i]);
}
{
int piv = 0;
rep(i,0,n) {
for (int x: ikeru1[i]) {
g1[piv++] = x;
}
f1[i+1] = piv;
}
}
{
int piv = 0;
rep(i,0,n) {
for (int x: ikeru2[i]) {
g2[piv++] = x;
}
f2[i+1] = piv;
}
}
rep(st,0,n) {
{
fill(seen,seen+n,false);
int piv = 1;
mada[0] = st;
seen[st] = 1;
d1[st] = 0;
while (piv > 0) {
int i = mada[--piv];
rep(x,f1[i],f1[i+1]){
int j = g1[x];
if (!seen[j]) {
d1[j] = d1[i] + 1;
mada[piv++] = j;
seen[j] = 1;
}
}
}
}
{
fill(seen,seen+n,false);
int piv = 1;
mada[0] = st;
seen[st] = 1;
d2[st] = 0;
while (piv > 0) {
int i = mada[--piv];
rep(x,f2[i],f2[i+1]){
int j = g2[x];
if (!seen[j]) {
d2[j] = d2[i] + 1;
mada[piv++] = j;
seen[j] = 1;
}
}
}
}
rep(i,st+1,n){
ans += d1[i] * d2[i];
}
}
ans *= 2;
cout << ans << endl;
}
shobonvip