結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2016-08-27 01:01:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,871 bytes |
| コンパイル時間 | 1,204 ms |
| コンパイル使用メモリ | 87,136 KB |
| 実行使用メモリ | 34,304 KB |
| 最終ジャッジ日時 | 2024-11-08 18:13:53 |
| 合計ジャッジ時間 | 11,817 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 20 |
ソースコード
#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;
}
どらら