結果

問題 No.416 旅行会社
ユーザー PulmnPulmn
提出日時 2018-07-07 12:20:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 636 ms / 4,000 ms
コード長 1,428 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 159,200 KB
実行使用メモリ 17,876 KB
最終ジャッジ日時 2023-08-21 10:20:19
合計ジャッジ時間 10,415 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
11,524 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 32 ms
4,436 KB
testcase_10 AC 307 ms
11,736 KB
testcase_11 AC 303 ms
14,452 KB
testcase_12 AC 306 ms
14,648 KB
testcase_13 AC 276 ms
14,688 KB
testcase_14 AC 636 ms
16,756 KB
testcase_15 AC 627 ms
17,284 KB
testcase_16 AC 616 ms
17,876 KB
testcase_17 AC 622 ms
16,972 KB
testcase_18 AC 636 ms
16,960 KB
testcase_19 AC 439 ms
13,848 KB
testcase_20 AC 434 ms
13,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,q;
set<P> st;
vi s,t,a;
vvi g;

void dfs(int v,int c){
	if(a[v]!=-1) return;
	a[v]=c;
	for(auto u:g[v]) if(a[u]==-1) dfs(u,c);
}

int main(){
	cin>>n>>m>>q;
	g=vvi(n);
	a=vi(n,-1);
	s=t=vi(q);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		st.insert({u,v});
	}
	for(int i=0;i<q;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		st.erase({u,v});
		s[i]=u,t[i]=v;
	}
	for(auto i=st.begin();i!=st.end();i++){
		int u=i->first,v=i->second;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,0);
	for(int i=1;i<=q;i++){
		int u=s[q-i],v=t[q-i];
		g[u].push_back(v);
		g[v].push_back(u);
		if(a[u]!=-1||a[v]!=-1){
			dfs(u,i);dfs(v,i);
		}
	}
	for(int i=1;i<n;i++){
		if(a[i]==-1) cout<<0<<endl;
		else if(a[i]==0) cout<<-1<<endl;
		else cout<<q-a[i]+1<<endl;
	}
}
0