結果
問題 | No.416 旅行会社 |
ユーザー | naimonon77 |
提出日時 | 2016-10-30 13:27:35 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,051 bytes |
コンパイル時間 | 2,255 ms |
コンパイル使用メモリ | 185,524 KB |
実行使用メモリ | 16,376 KB |
最終ジャッジ日時 | 2023-08-16 11:16:55 |
合計ジャッジ時間 | 10,742 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 266 ms
11,804 KB |
testcase_01 | AC | 5 ms
5,848 KB |
testcase_02 | AC | 4 ms
5,844 KB |
testcase_03 | AC | 4 ms
5,972 KB |
testcase_04 | AC | 5 ms
5,904 KB |
testcase_05 | AC | 5 ms
6,068 KB |
testcase_06 | AC | 5 ms
5,876 KB |
testcase_07 | AC | 7 ms
6,108 KB |
testcase_08 | AC | 10 ms
6,228 KB |
testcase_09 | AC | 36 ms
6,716 KB |
testcase_10 | AC | 295 ms
11,716 KB |
testcase_11 | AC | 293 ms
11,720 KB |
testcase_12 | AC | 292 ms
11,716 KB |
testcase_13 | AC | 265 ms
11,760 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | AC | 437 ms
14,844 KB |
testcase_20 | AC | 423 ms
14,616 KB |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(int i=a;i<b;++i) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define ALL(a) begin(a),end(a) #define ifnot(a) if(not (a)) #define dump(x) cerr << #x << " = " << (x) << endl using namespace std; // #define int ll #ifdef _MSC_VER const bool test = true; #else const bool test = false; #endif int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; #define INF (1 << 28) ull mod = (int)1e9 + 7; //..................... const int MAX = (int)1e5 + 5; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) { } bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int N, M, Q; set<pair<int, int>> bridge; pair<int, int> broken[MAX]; int ans[MAX]; UnionFind uf(MAX); vector<vector<int>> g2i(MAX); int main() { int i, j, k; cin >> N >> M >> Q; rep(i, M) { int a, b; cin >> a >> b; a--; b--; bridge.insert({ a,b }); } rep(i, Q) { int c, d; cin >> c >> d; c--; d--; broken[i] = { c,d }; } for (auto c : broken) { bridge.erase(c); } auto alive = bridge; for (auto c : alive) { uf.unite(c.first, c.second); } rep(i, N) { g2i[uf.root(i)].push_back(i); } rep(i, N) { if (uf.same(i, 0)) { ans[i] = -1; } } for (i = Q - 1; i > -1; i--) { int x = uf.root(broken[i].first); int y = uf.root(broken[i].second); if (uf.same(x, y)) continue; if (uf.same(0, y)) swap(x, y); if (uf.same(0, x)) { for (auto v : g2i[y]) { ans[v] = i + 1; // ? } } if (uf.size(x) < uf.size(y)) swap(x, y); g2i[x].insert(g2i[x].end(), ALL(g2i[y])); uf.unite(x, y); } REP(i, 1, N) { cout << ans[i] << endl; } return 0; }