結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-09-18 20:57:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,619 bytes |
| コンパイル時間 | 1,352 ms |
| コンパイル使用メモリ | 118,092 KB |
| 実行使用メモリ | 863,888 KB |
| 最終ジャッジ日時 | 2024-11-17 09:02:47 |
| 合計ジャッジ時間 | 23,687 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 2 MLE * 1 |
ソースコード
//
// main.cpp
// No416
//
// Created by nanophoto on 2016/09/18.
// Copyright © 2016年 nanophoto. All rights reserved.
//
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
using namespace std;
#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<int,int>
#define REP(x,n) for(int x = 0;x < n;x++)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
struct UnionFind {
map<int, unordered_set<int>> m;
map<int, int> data;
UnionFind(int size)
{
for(int i = 0;i < size;i++)
{
data[i] = i;
m[i].insert(i);
}
}
bool unionSet(int x, int y, vector<int>& v, int times) {
x = root(x); y = root(y);
if (x != y) {
int l = min(x, y);
int u = max(x, y);
for(auto& e : m[u])
{
m[l].insert(e);
if(l == 0)
{
v[e] = times;
}
}
data[u] = l;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
if(data[x] == x)
{
return x;
}
data[x] = root(data[x]);
return data[x];
}
};
const ll mod = (ll)(1e6+7);
struct SimpleHash {
size_t operator()(const std::pair<int, int>& p) const {
return p.first * mod + p.second;
}
};
unordered_set<pii, SimpleHash> ad;
vector<pii> rem;
int main() {
int n, m, q;
cin >> n >> m >> q;
REP(x,m)
{
int a, b;
cin >> a >> b;
a--;
b--;
ad.insert(make_pair(a,b));
}
REP(x,q)
{
int a, b;
cin >> a >> b;
a--;
b--;
rem.push_back(make_pair(a,b));
}
for(auto& e : rem)
{
ad.erase(e);
}
UnionFind uf(n);
vector<int> v(n);
fill(v.begin(), v.end(), 0);
for(auto& e : ad)
{
uf.unionSet(e.first, e.second, v, -1);
}
for(int i = q-1; i >= 0;i--)
{
uf.unionSet(rem[i].first, rem[i].second, v, i + 1);
//for(int k = 0;k < n;k++)
//{
// cout << " " << k << " " << uf.root(k) << endl;
//}
//cout << endl;
}
for(int i = 1;i < n;i++)
{
cout << v[i] << endl;
}
}
nanophoto12