結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2016-08-28 11:30:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 608 ms / 4,000 ms |
| コード長 | 1,483 bytes |
| コンパイル時間 | 1,297 ms |
| コンパイル使用メモリ | 108,704 KB |
| 実行使用メモリ | 18,284 KB |
| 最終ジャッジ日時 | 2024-12-14 20:08:30 |
| 合計ジャッジ時間 | 8,057 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second
#define INF 2147483600
typedef pair<int, int> P;
int main(){
int n,m,q;
cin>>n>>m>>q;
set<P> brg;
rep(i,m){
int a,b;
scanf("%d %d", &a, &b);
a--;b--;
brg.insert(mp(a,b));
}
vector<vector<P> > vec(n, vector<P>());
// to, weight
rep(i,q){
int a,b;
scanf("%d %d", &a, &b);
a--;b--;
vec[a].pb(mp(b, i+1));
vec[b].pb(mp(a, i+1));
brg.erase(mp(a,b));
}
for(P p: brg){
int a=p.fi, b=p.se;
vec[a].pb(mp(b,INF));
vec[b].pb(mp(a,INF));
}
vector<int> res(n, -INF);
vector<bool> visited(n, false);
priority_queue<P> pq;
// <weight, to>
for(P p: vec[0]) pq.push(mp(p.se, p.fi));
while(!pq.empty()){
P p = pq.top(); pq.pop();
int now = p.se, w = p.fi;
if(res[now] >= w) continue;
res[now] = w;
for(P nxt: vec[now]) pq.push(mp(min(w, nxt.se), nxt.fi));
}
repl(i,1,n){
if(res[i]==INF) res[i]=-1;
if(res[i]==-INF) res[i]=0;
cout<<res[i]<<endl;
}
return 0;
}
tossy