結果
問題 | No.416 旅行会社 |
ユーザー |
![]() |
提出日時 | 2019-03-03 14:36:09 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 765 ms / 4,000 ms |
コード長 | 2,051 bytes |
コンパイル時間 | 1,130 ms |
コンパイル使用メモリ | 88,288 KB |
実行使用メモリ | 25,472 KB |
最終ジャッジ日時 | 2024-12-14 20:34:57 |
合計ジャッジ時間 | 9,829 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <iostream>#include <algorithm>#include <cstring>#include <sstream>#include <map>#include <queue>#include <set>#include <vector>#include <stack>#include <cstdio>#include <cmath>#define mk make_pair#define pb push_back#define printf printf_s#define scanf scanf_susing namespace std;typedef long long int ll;typedef pair<ll, ll> pos;const ll MOD = 1000000007, N = 100001, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;ll mn(ll a, ll b) {if (a == -1)return b;if (b == -1)return a;return min(a, b);}ll gcd(ll v1, ll v2) {if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);}ll pw(ll v1, ll v2) {ll v3 = 1;while (v2 > 0) {if (v2 % 2)v3 = (v3*v1) % MOD;v1 = (v1*v1) % MOD;v2 /= 2;}return v3;}struct ab {ll a, b;bool operator<(const ab& right) const {return right.b*a - right.a*b < 0;}};ll n,m,Q,ind[N],ans[N];vector<ll> g[N];pos cd[N * 2],ab[N*2];map<pos,bool> st;void src(ll ind, ll v1) {queue<ll> q;q.push(ind);ans[ind] = v1;while (!q.empty()) {ll v2 = q.front(); q.pop();for (int i = 0; i < g[v2].size(); i++) {if (ans[g[v2][i]] ==-2) {ans[g[v2][i]] = v1;q.push(g[v2][i]);}}}}int main() {cin >> n >> m >> Q;for (int i = 0; i < m; i++) { cin >> ab[i].first >> ab[i].second; st[ab[i]] = true; }for (int i = 0; i < Q; i++) {cin >> cd[i].first >> cd[i].second;st[cd[i]] = false;}for (int i = 0; i < m; i++) {if (st[ab[i]]) {g[ab[i].first].pb(ab[i].second);g[ab[i].second].pb(ab[i].first);}}st.clear();for (int i = 1; i <= n; i++)ans[i] = -2;src(1, -1);for (int i = Q - 1; i >= 0; i--) {ll v1=cd[i].first, v2=cd[i].second;if (ans[v2] != -2&&ans[v1] == -2) {src(v1, i + 1);}if (ans[v1] != -2&&ans[v2] == -2) {src(v2, i + 1);}g[v1].pb(v2);g[v2].pb(v1);}for (int i = 1; i <= n; i++) { if (ans[i] == -2)ans[i] = 0; }for (int i = 2; i <= n; i++)cout << ans[i] << endl;return 0;}