| Task: | Ice cream |
| Sender: | emlai |
| Submission time: | 2016-09-20 18:50:20 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.07 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | ACCEPTED | 0.05 s | details |
| #6 | ACCEPTED | 0.08 s | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | ACCEPTED | 0.10 s | details |
| #11 | ACCEPTED | 0.11 s | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
| #14 | TIME LIMIT EXCEEDED | -- | details |
| #15 | ACCEPTED | 0.10 s | details |
| #16 | ACCEPTED | 0.10 s | details |
| #17 | TIME LIMIT EXCEEDED | -- | details |
| #18 | TIME LIMIT EXCEEDED | -- | details |
| #19 | TIME LIMIT EXCEEDED | -- | details |
| #20 | ACCEPTED | 0.11 s | details |
Code
#include <vector>
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <unordered_set>
using namespace std;
using ll = long long;
vector<ll> icecreams;
unordered_map<ll, vector<ll>> connections;
namespace std {
template<typename a, typename b>
struct hash< std::pair<a, b> > {
private:
const hash<a> ah;
const hash<b> bh;
public:
hash() : ah(), bh() {}
size_t operator()(const std::pair<a, b> &p) const {
return ah(p.first) ^ bh(p.second);
}
};
} // namespaces
void recursion(ll city, unordered_set<ll>& hasaccess, unordered_set<ll>& visited)
{
if (visited.count(city) == 1) return;
hasaccess.insert(icecreams.at(city-1));
visited.insert(city);
for (const ll dst : connections[city])
{
recursion(dst, hasaccess, visited);
}
}
void connectRoads(const ll a, const ll b, unordered_set<std::pair<ll,ll>>& visited)
{
const auto p = std::make_pair(a,b);
if (visited.count(p) == 1) return;
visited.insert(p);
for (const ll neighborOfA : connections[a])
connectRoads(neighborOfA, b, visited);
for (const ll neighborOfB : connections[b])
connectRoads(a, neighborOfB, visited);
connections[a].push_back(b);
connections[b].push_back(a);
}
int main()
{
ll n,m;
cin>>n>>m;
icecreams.resize(n);
for (int i=0; i<n; ++i)
cin>>icecreams.at(i);
for (int i=0; i<m; ++i)
{
ll a,b;
cin>>a>>b;
unordered_set<std::pair<ll,ll>> visited;
connectRoads(a,b,visited);
}
for (int i=1; i<=n; ++i)
{
unordered_set<ll> hasaccess;
unordered_set<ll> visited;
recursion(i, hasaccess, visited);
cout << hasaccess.size() << ' ';
}
cout << '\n';
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 47623 1000 6085 3581 2784 1594 9991 7789 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 29933 10000 37075 97477 24892 91827 86196 ... |
| correct output |
|---|
| 2 6 1 1 5 1 1 7 9 2 2 2 1 1 3 ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 82771 50000 84 19 10 43 44 51 77 9 4 1 21 ... |
| correct output |
|---|
| 2 1 1 1 100 1 1 1 100 100 1 1 ... |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 11645 100000 3041 8953 9167 1268 2312 5911 ... |
| correct output |
|---|
| 6836 6836 6836 6836 6836 6836 ... |
| user output |
|---|
| (empty) |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 1041 100 43553 8035 14355 19335 24786 7... |
| correct output |
|---|
| 2 1 1 3 1 1 1 2 1 1 1 1 3 1 1 ... |
| user output |
|---|
| 2 1 1 3 1 1 1 2 1 1 1 1 3 1 1 ... |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 55898 1000 73 44 15 26 63 51 15 71 73 48 ... |
| correct output |
|---|
| 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ... |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 12027 10000 2456 845 5196 3813 3093 2331 2... |
| correct output |
|---|
| 2 5542 5542 1 5542 5542 5542 5... |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 55977 50000 79310 84043 72794 74090 312 15... |
| correct output |
|---|
| 1 33498 33498 33498 33498 1 1 ... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 16237 100000 57 43 3 66 59 10 24 41 56 23 5... |
| correct output |
|---|
| 100 100 100 100 100 100 100 10... |
| user output |
|---|
| (empty) |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 93552 100 31 7952 1106 2779 1980 8776 56... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 100000 1000 99793 93845 56091 42020 27225 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 10000 45 12 5 45 21 73 12 34 97 14 6... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 50000 3967 8608 4873 6065 3304 1388 ... |
| correct output |
|---|
| 27 10 2 1 205 2 1 5 752 9 2 26... |
| user output |
|---|
| (empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 70000 100000 9570 57890 88434 83611 76325 3... |
| correct output |
|---|
| 1 1 1 47966 47966 47966 47966 ... |
| user output |
|---|
| (empty) |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 100000 100 84 34 32 36 64 83 29 4 36 57 9... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 100000 1000 7080 7863 895 4001 3806 8637 7... |
| correct output |
|---|
| 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 17
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 10000 13821 30085 25414 18462 40885 ... |
| correct output |
|---|
| 1 1 3 1 1 2 1 1 1 2 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 18
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 50000 41 89 12 33 73 79 38 48 90 68 ... |
| correct output |
|---|
| 4 1 21 1 2 2 1 1 3 2 3 7 6 20 ... |
| user output |
|---|
| (empty) |
Test 19
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 100000 4325 2304 2625 9099 4244 1618 ... |
| correct output |
|---|
| 9994 5 9994 9994 9994 1 9994 9... |
| user output |
|---|
| (empty) |
Test 20
Verdict: ACCEPTED
| input |
|---|
| 100000 100 68725 58766 50437 78768 4415 2... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
