結果

問題 No.416 旅行会社
ユーザー kurenai3110kurenai3110
提出日時 2016-08-27 00:28:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,011 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 69,956 KB
実行使用メモリ 25,352 KB
最終ジャッジ日時 2024-04-26 04:46:12
合計ジャッジ時間 11,599 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

static const int MAX = 200000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX/2];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top(); S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == c-1) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	for (int i = 1; i <= n; i++) color[i] = NIL;
	dfs(1, 1);
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;

	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	assignColor();

	int c, d;
	for (int i = 0; i < q; i++) {
		cin >> c >> d;
		G[c].erase(find(G[c].begin(), G[c].end(), d));
		G[d].erase(find(G[d].begin(), G[d].end(), c));
		dfs(1, i + 2);
	}

	for (int i = 2; i <= n; i++) {
		if (color[i] == q+1)cout << -1 << endl;
		else cout << color[i] << endl;
	}

	return 0;
}
0