結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-17 13:59:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,014 bytes |
| コンパイル時間 | 1,910 ms |
| コンパイル使用メモリ | 180,584 KB |
| 実行使用メモリ | 23,728 KB |
| 最終ジャッジ日時 | 2024-10-11 11:00:11 |
| 合計ジャッジ時間 | 7,054 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 8 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
vector<int> parents(100010,-1);
vector<vector<int>> child(100010);
vector<int> when(100010,-1);
int t = -1;
int find(int i) {
if (parents[i] < 0) return i;
return parents[i] = find(parents[i]);
}
void unite(int x,int y) {
x = find(x); y = find(y);
if (x == y) return;
if (x == 0) {
for (int c:child[y]) {
when[c] = t;
child[0].push_back(c);
}
parents[x] += parents[y];
parents[y] = x;
} else if (y == 0) {
for (int c:child[x]) {
when[c] = t;
child[0].push_back(c);
}
parents[y] += parents[x];
parents[x] = y;
} else {
if (parents[x] > parents[y]) swap(x,y);
for (int c:child[y]) {
child[x].push_back(c);
}
parents[x] += parents[y];
parents[y] = x;
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N,M,Q; cin >> N >> M >> Q;
rep(i,N) child[i].push_back(i);
vector<P> bridge(M),broken(Q);
set<P> st;
rep(i,M) {
cin >> bridge[i].first >> bridge[i].second;
bridge[i].first--; bridge[i].second--;
}
rep(i,Q) {
cin >> broken[i].first >> broken[i].second;
broken[i].first--; broken[i].second--;
st.insert(broken[i]);
}
rep(i,M) {
if (!st.count(bridge[i])) unite(bridge[i].first,bridge[i].second);
}
t = Q;
for (;t >= 1;--t) {
unite(broken[t - 1].first,broken[t - 1].second);
}
for (int i = 1;i < N;++i) cout << when[i] << '\n';
return 0;
}