結果
| 問題 |
No.3309 Aging Railway
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-24 21:55:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,686 bytes |
| コンパイル時間 | 2,935 ms |
| コンパイル使用メモリ | 289,896 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-10-24 21:55:50 |
| 合計ジャッジ時間 | 5,720 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define TT template <typename T>
template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(15);
srand(time(NULL));
}
} io_setup;
void solve() {
int N, M;
cin >> N >> M;
vector<int> U(N - 1), V(N - 1);
rep(i, 0, N - 1) {
cin >> U[i] >> V[i];
U[i]--;
V[i]--;
}
vector flag(N, vector<bool>(N));
rep(i, 0, M) {
int s, t;
cin >> s >> t;
s--;
t--;
flag[s][t] = true;
flag[t][s] = true;
}
vector<vector<int>> G(N);
vector<int> id(N);
rep(i, 0, N) {
G[i].push_back(i);
id[i] = i;
}
vector<int> ans(N - 1);
rrep(k, 0, N - 1) {
int u = id[U[k]], v = id[V[k]];
assert(u != v);
if (G[u].size() > G[v].size()) {
swap(u, v);
}
for (auto x : G[v]) {
G[u].push_back(x);
id[x] = u;
if (flag[u][x]) {
ans[0]++;
ans[k]--;
}
}
G[v].clear();
}
rep(k, 0, N - 2) ans[k + 1] += ans[k];
rep(k, 0, N - 1) cout << ans[k] << "\n";
}
int main() {
solve();
}