結果

問題 No.416 旅行会社
ユーザー どららどらら
提出日時 2016-08-27 01:01:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,871 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 88,684 KB
実行使用メモリ 37,384 KB
最終ジャッジ日時 2024-04-26 05:29:15
合計ジャッジ時間 11,679 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 99999999

int N, M, Q;
map<int,int> G[200005];
int ret[200005];
int cost[200005];
bool visited[200005];

void dijkstra(){
  rep(i,200005){
    ret[i] = -INF;
    cost[i] = INF;
    visited[i] = false;
  }
  cost[0] = Q+1;

  while(true){
    int maxPos, maxVal = -1;

    rep(i,N){
      if(cost[i] != INF && maxVal<cost[i] && !visited[i]){
        maxVal = cost[i];
        maxPos = i;
      }
    }
    if(maxVal == -1) break;
    //cout << "\t" << maxPos << " " << maxVal << endl;
    //cout << "\t"; rep(i,N) cout << cost[i] << "\t"; cout << endl;
    
    visited[maxPos] = true;
    ret[maxPos] = maxVal;

    FOR(it, G[maxPos]){
      int nxt = it->first;
      int cst = min(maxVal, it->second);
      if(cst == -1) cst = maxVal;
      
      if(cost[nxt] == INF){
        cost[nxt] = cst;
      }else{
        cost[nxt] = max(cost[nxt], cst);
      }
    }
  }
}

int main(){
  ios::sync_with_stdio(false);

  cin >> N >> M >> Q;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a][b] = -1;
    G[b][a] = -1;
  }

  rep(i,Q){
    int c, d;
    cin >> c >> d;
    c--; d--;
    G[c][d] = i+1;
    G[d][c] = i+1;
  }

  dijkstra();

  REP(i,1,N){
    if(ret[i] == -INF){
      cout << 0 << endl;
    }
    else if(ret[i] == Q+1){
      cout << -1 << endl;
    }else{
      cout << ret[i] << endl;
    }
  }
  
  return 0;
}

0