結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2016-08-27 00:28:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,011 bytes |
| コンパイル時間 | 2,649 ms |
| コンパイル使用メモリ | 68,536 KB |
| 実行使用メモリ | 21,888 KB |
| 最終ジャッジ日時 | 2024-11-08 17:25:26 |
| 合計ジャッジ時間 | 12,171 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 20 |
ソースコード
#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;
}
kurenai3110