結果

問題 No.416 旅行会社
ユーザー 193s
提出日時 2017-11-13 22:19:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 383 ms / 4,000 ms
コード長 1,850 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 109,360 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2024-12-14 20:25:54
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M, Q;
int U[100000], R[100000], T[100000];
int find(int x) {
if (U[x] == x) return x;
return find(U[x]);
}
void unite(int x, int y, int t) {
x = find(x), y = find(y);
if (x == y) return;
if (R[x] > R[y]) swap(x, y);
U[x] = y;
T[x] = min(T[x], t);
if (R[x] == R[y]) R[y]++;
}
int find(int x, int t) {
if (T[x] > t) return x;
return find(U[x], t);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M >> Q;
map<P, int> mp;
rep(i, M) {
int a, b;
cin >> a >> b;
a--, b--;
mp[P(a, b)] = 0;
}
rep(i, Q) {
int a, b;
cin >> a >> b;
a--, b--;
if (mp.find(P(a, b)) == mp.end()) swap(a, b);
mp[P(a, b)] = Q-i;
}
rep(i, N) U[i] = i, R[i] = 1, T[i] = INF;
vector<pair<int, P> > pp;
for (auto p : mp) pp.pb(make_pair(p._2, P(p._1._1, p._1._2)));
sort(all(pp));
for (auto p : pp) unite(p._2._1, p._2._2, p._1);
for (int i=1; i<N; i++) {
if (find(0, Q) != find(i, Q)) {
cout << 0 << "\n";
continue;
}
int lo = -1, hi = Q+1;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (find(0, mid) == find(i, mid)) hi = mid;
else lo = mid;
}
if (hi == 0) cout << -1 << "\n";
else cout << Q+1-hi << "\n";
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0