結果

問題 No.416 旅行会社
ユーザー kurenai3110kurenai3110
提出日時 2016-08-27 00:19:16
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,009 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 69,304 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-26 04:20:30
合計ジャッジ時間 11,562 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 3 ms
5,760 KB
testcase_02 AC 3 ms
5,760 KB
testcase_03 AC 4 ms
5,760 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
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 = 100000;
static const int NIL = -1;

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

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, 0);
}

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 + 1);
	}

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

	return 0;
}
0