結果

問題 No.416 旅行会社
ユーザー どららどらら
提出日時 2016-08-27 00:19:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,710 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 85,144 KB
実行使用メモリ 20,448 KB
最終ジャッジ日時 2024-04-26 04:21:05
合計ジャッジ時間 11,850 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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;
vector< pair<int,int> > G[200005];
int ret[200005];
bool visited[200005];

void dijkstra(){
  rep(i,200005){
    ret[i] = INF;
    visited[i] = false;
  }
  ret[0] = 0;

  while(true){
    int minPos, minVal = INF;

    rep(i,N){
      if(minVal>ret[i] && !visited[i]){
        minVal = ret[i];
        minPos = i;
      }
    }
    if(minVal == INF) break;

    visited[minPos] = true;

    rep(i,G[minPos].size()){
      int nxt = G[minPos][i].first;
      int cst = G[minPos][i].second;
      if(ret[nxt] == INF){
        ret[nxt] = cst;
      }else{
        ret[nxt] = max(ret[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].push_back(make_pair(b, -1));
    G[b].push_back(make_pair(a, -1));
  }

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

  dijkstra();

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

0