結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
Pulmn
|
| 提出日時 | 2018-07-07 12:21:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 466 ms / 4,000 ms |
| コード長 | 1,467 bytes |
| コンパイル時間 | 1,683 ms |
| コンパイル使用メモリ | 173,192 KB |
| 実行使用メモリ | 18,432 KB |
| 最終ジャッジ日時 | 2024-12-14 20:30:55 |
| 合計ジャッジ時間 | 7,422 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#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(){
ios::sync_with_stdio(0);
cin.tie(0);
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;
}
}
Pulmn