結果
問題 | No.416 旅行会社 |
ユーザー |
![]() |
提出日時 | 2017-01-13 23:12:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 961 ms / 4,000 ms |
コード長 | 2,602 bytes |
コンパイル時間 | 1,303 ms |
コンパイル使用メモリ | 118,876 KB |
実行使用メモリ | 53,900 KB |
最終ジャッジ日時 | 2024-12-14 20:24:28 |
合計ジャッジ時間 | 11,154 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include "math.h"#include <algorithm>#include <complex>#include <cstdio>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <set>#include <string>#include <vector>#define ifor(i, a, b) for (int i = (a); i < (b); i++)#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)#define rep(i, n) for (int i = 0; i < (n); i++)#define all(a) (a).begin(), (a).end()#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)#define SIZE 200005#define UF_MAX 100005using namespace std;typedef long double ld;typedef long long int lli;const double eps = 1e-11;int vex[4] = {1, 0, -1, 0};int vey[4] = {0, 1, 0, -1};lli MOD = 1000000007;int turn = 0;int ans[100005] = {};#define UF_MAX 100005struct UFind {int par[UF_MAX];int rank[UF_MAX];int count[UF_MAX];set<int> st[UF_MAX]; //parが全部持つUFind(int n){rep(i, n){par[i] = i;rank[i] = 0;st[i].insert(i);count[i] = 1;}}int find(int x){if (par[x] == x) {return x;} else {return par[x] = find(par[x]);}}void unite(int x, int y){x = find(x);y = find(y);if (x == y)return;if (same(x, 0) && !same(y, 0)) {for (auto s : st[y])ans[s] = turn;} else if (!same(x, 0) && same(y, 0)) {for (auto s : st[x])ans[s] = turn;}if (st[x].size() > st[y].size()) {for (auto s : st[y])st[x].insert(s);par[y] = x;} else {for (auto s : st[x])st[y].insert(s);par[x] = y;}}bool same(int x, int y){return find(x) == find(y);}};int main(){map<int, map<int, int>> edge;int n, m, q;cin >> n >> m >> q;int a, b;UFind uf(n);rep(i, m){cin >> a >> b;a--, b--;edge[a][b] = -1;}vector<pair<int, int>> query;rep(i, q){cin >> a >> b;a--, b--;edge[a][b] = 1;edge[b][a] = 1;query.push_back(make_pair(a, b));}turn = -1;for (auto s : edge)for (auto t : s.second)if (t.second == -1)uf.unite(s.first, t.first);reverse(all(query));turn = q;rep(i, q){uf.unite(query[i].first, query[i].second);turn--;}rep(i, n - 1){cout << ans[i + 1] << endl;}}