結果
問題 | No.416 旅行会社 |
ユーザー | pione |
提出日時 | 2020-04-30 04:39:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,238 bytes |
コンパイル時間 | 1,793 ms |
コンパイル使用メモリ | 183,456 KB |
実行使用メモリ | 29,820 KB |
最終ジャッジ日時 | 2024-05-08 03:00:24 |
合計ジャッジ時間 | 8,618 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout<<d<<endl; #define coutd(d) cout<<std::setprecision(10)<<d<<endl; #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9+7; const ll LINF = 1e18; class UnionFind{ private: vector<ll> Parent; public: UnionFind(ll N){ Parent = vector<ll>(N, -1); } ll root(ll A){ if(Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } ll size(ll A){ return -Parent[root(A)]; } bool connect(ll A, ll B){ A = root(A); B = root(B); if(A == B){ return false; } if(size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = A; return true; } bool isSame(ll A, ll B){ return root(A) == root(B); } }; ll n,m,q; vll G[100100]; bool visited[100100]; ll res[100100]; void dfs(ll v, ll p, ll c){ res[v]=c; visited[v]=true; for(auto nv: G[v]){ if(nv==p) continue; if(visited[nv]) continue; dfs(nv,v,c); } } signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); cin>>n>>m>>q; vpll ab(m); rep(i,m){ ll a,b; cin>>a>>b; a--,b--; ab[i]={a,b}; } vpll cd(q); set<pll> s; rep(i,q){ ll c,d; cin>>c>>d; c--,d--; cd[i]={c,d}; s.insert({c,d}); } UnionFind uf(n); rep(i,m){ if(!s.count(ab[i])){ ll a,b; tie(a,b)=ab[i]; G[a].push_back(b); G[b].push_back(a); uf.connect(a,b); } } rep(i,n){ if(uf.isSame(0,i)){ visited[i]=true; res[i]=-1; } } rep(i,n){ if(i) cout<<' '; cout<<res[i]; } cout<<endl; // reverse(all(cd)); rrep(i,q){ ll c,d; tie(c,d)=cd[i]; if(!uf.isSame(c,d)){ G[c].push_back(d); G[d].push_back(c); if(uf.isSame(0,c)) dfs(d,-1,i+1); if(uf.isSame(0,d)) dfs(c,-1,i+1); uf.connect(c,d); } } irep(i,1,n){ cout<<res[i]<<endl; } }