結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-09-18 21:21:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,790 bytes |
| コンパイル時間 | 1,313 ms |
| コンパイル使用メモリ | 102,392 KB |
| 実行使用メモリ | 813,948 KB |
| 最終ジャッジ日時 | 2024-11-17 09:04:35 |
| 合計ジャッジ時間 | 11,450 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 MLE * 2 |
ソースコード
//
// main.cpp
// No416
//
// Created by nanophoto on 2016/09/18.
// Copyright © 2016年 nanophoto. All rights reserved.
//
#include <cmath>
#include <vector>
#include <map>
#include <set>
#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 {
vector<int> m[(int)(1e6+1)];
int data[(int)(1e6+1)];
UnionFind(int size)
{
for(int i = 0;i < size;i++)
{
data[i] = i;
m[i].push_back(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].push_back(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;
}
};
vector<int> ad[(int)1e6+1];
set<int> rem[(int)1e6+1];
vector<pii> qs;
int main() {
int n, m, q;
cin >> n >> m >> q;
REP(x,m)
{
int a, b;
cin >> a >> b;
a--;
b--;
ad[a].push_back(b);
}
REP(x,q)
{
int a, b;
cin >> a >> b;
a--;
b--;
rem[a].insert(b);
qs.push_back(make_pair(a,b));
}
UnionFind uf(n);
vector<int> v(n);
fill(v.begin(), v.end(), 0);
for(int i = 0;i < n;i++)
{
for(int j = 0;j < ad[i].size();j++)
{
int k = ad[i][j];
if(rem[i].find(k) == rem[i].end())
{
uf.unionSet(i, k, v, -1);
}
}
}
for(int i = q-1; i >= 0;i--)
{
uf.unionSet(qs[i].first, qs[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