結果
問題 | No.416 旅行会社 |
ユーザー | tempura_pp |
提出日時 | 2019-06-29 15:21:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 316 ms / 4,000 ms |
コード長 | 2,025 bytes |
コンパイル時間 | 1,041 ms |
コンパイル使用メモリ | 110,168 KB |
実行使用メモリ | 14,600 KB |
最終ジャッジ日時 | 2023-08-21 10:25:57 |
合計ジャッジ時間 | 5,113 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
9,040 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,384 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 4 ms
4,380 KB |
testcase_09 | AC | 14 ms
4,376 KB |
testcase_10 | AC | 105 ms
8,684 KB |
testcase_11 | AC | 101 ms
8,672 KB |
testcase_12 | AC | 104 ms
8,584 KB |
testcase_13 | AC | 86 ms
8,996 KB |
testcase_14 | AC | 316 ms
14,016 KB |
testcase_15 | AC | 302 ms
14,008 KB |
testcase_16 | AC | 302 ms
14,600 KB |
testcase_17 | AC | 311 ms
13,844 KB |
testcase_18 | AC | 314 ms
13,992 KB |
testcase_19 | AC | 199 ms
12,028 KB |
testcase_20 | AC | 201 ms
12,132 KB |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<unordered_map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ; struct ppUF{ vector<int> ra,par,ti; ppUF(int n){ ra.resize(n,0); ti.resize(n,inf+1); par.resize(n,-1); } int find(int t,int x){ if(ti[x]>t)return x; return find(t,par[x]); } bool unite(int t,int x,int y){ x=find(t,x);y=find(t,y); if(x==y)return false; if(ra[x]>ra[y]){ par[y]=x; ti[y]=t; } else{ par[x]=y; ti[x]=t; if(ra[x]==ra[y])ra[y]++; } return true; } bool same(int t,int x,int y){ return find(t,x)==find(t,y); } int time(int x,int y){ if(!same(202020,x,y))return -1; int ok=202020,ng=-1,mid=0; while(ok-ng>1){ mid=(ok+ng)/2; if(same(mid,x,y))ok=mid; else ng=mid; } return ok; } }; int main(){ int n,m,q; cin>>n>>m>>q; set<pint> st; rep(i,m){ int x,y; scanf("%d%d",&x,&y); st.insert({x,y}); } pair<int,int> p[q]; rep(i,q){ int x,y; scanf("%d%d",&x,&y); p[q-i-1]={x,y}; st.erase({x,y}); } ppUF uf(n+1); for(auto e : st){ uf.unite(0, e.first, e.second); } rep(i,q){ uf.unite(i+1, p[i].first, p[i].second); } rep(i,n-1){ int ret=uf.time(1, i+2); if(ret==-1)ret=0; else if(ret==0)ret=-1; else ret=q+1-ret; printf("%d\n",ret); } return 0; }