結果

問題 No.416 旅行会社
ユーザー azbrugbyazbrugby
提出日時 2019-03-03 14:36:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 749 ms / 4,000 ms
コード長 2,051 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 88,104 KB
実行使用メモリ 25,488 KB
最終ジャッジ日時 2023-08-21 10:22:23
合計ジャッジ時間 10,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 308 ms
18,456 KB
testcase_01 AC 3 ms
7,836 KB
testcase_02 AC 4 ms
7,980 KB
testcase_03 AC 3 ms
7,832 KB
testcase_04 AC 3 ms
7,936 KB
testcase_05 AC 3 ms
7,848 KB
testcase_06 AC 3 ms
7,852 KB
testcase_07 AC 4 ms
7,904 KB
testcase_08 AC 9 ms
8,168 KB
testcase_09 AC 36 ms
9,088 KB
testcase_10 AC 351 ms
18,504 KB
testcase_11 AC 344 ms
18,504 KB
testcase_12 AC 346 ms
18,624 KB
testcase_13 AC 304 ms
18,580 KB
testcase_14 AC 723 ms
25,284 KB
testcase_15 AC 730 ms
25,344 KB
testcase_16 AC 734 ms
25,300 KB
testcase_17 AC 749 ms
25,488 KB
testcase_18 AC 728 ms
25,308 KB
testcase_19 AC 547 ms
24,524 KB
testcase_20 AC 544 ms
24,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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_s
using 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;
}
0