結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2016-08-27 00:19:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,009 bytes |
| コンパイル時間 | 720 ms |
| コンパイル使用メモリ | 68,532 KB |
| 実行使用メモリ | 14,592 KB |
| 最終ジャッジ日時 | 2024-11-08 16:55:53 |
| 合計ジャッジ時間 | 7,273 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 6 RE * 1 TLE * 1 -- * 10 |
ソースコード
#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;
}
kurenai3110