結果

問題 No.416 旅行会社
ユーザー mint6421mint6421
提出日時 2019-08-21 23:20:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 450 ms / 4,000 ms
コード長 2,070 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 177,976 KB
実行使用メモリ 15,808 KB
最終ジャッジ日時 2023-08-21 10:25:22
合計ジャッジ時間 7,650 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
9,700 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 25 ms
4,380 KB
testcase_10 AC 225 ms
11,348 KB
testcase_11 AC 226 ms
15,808 KB
testcase_12 AC 226 ms
15,788 KB
testcase_13 AC 205 ms
14,232 KB
testcase_14 AC 443 ms
14,452 KB
testcase_15 AC 448 ms
15,304 KB
testcase_16 AC 450 ms
15,776 KB
testcase_17 AC 431 ms
15,264 KB
testcase_18 AC 433 ms
14,904 KB
testcase_19 AC 323 ms
14,176 KB
testcase_20 AC 314 ms
13,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
//#define int ll
#define vi vector<int>



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


UG es;
int ans[210000];
set<P> s;
vector<P> v;

void dfs(int k,int p,int x){
  ans[k]=x;
  for(int e:es[k]){
    if(e==p||ans[e]) continue;
    dfs(e,k,x);
  }

}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m,q;
  cin>>n>>m>>q;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    s.insert(P(a,b));
  }

  v = vector<P>(q);
  rep(i,q){
    cin>>v[i].F>>v[i].S;
    v[i].F--;v[i].S--;
    s.erase(P(v[i]));
  }

  es=UG(n);

  for(P p:s){
    es[p.F].PB(p.S);
    es[p.S].PB(p.F);
  }


  dfs(0,-1,-1);


  rrep(i,q-1){
    //cout<<i<<endl;
    //cout<<v[i].F<<' '<<v[i].S<<endl;
    if(ans[v[i].F]&&!ans[v[i].S]){
      
      dfs(v[i].S,-1,i+1);
    }else if(!ans[v[i].F]&&ans[v[i].S]){
      dfs(v[i].F,-1,i+1);
    }
    
    es[v[i].F].PB(v[i].S);
    es[v[i].S].PB(v[i].F);
    //rep(i,n) cout<<ans[i]<<' ';
    //cout<<endl;
  }

  FOR(i,1,n){
    cout<<ans[i]<<endl;
  }

  
}
0