Submission #1610574
Source Code Expand
#include <iostream> #include <vector> using namespace std; class up_tree { public: int n; int *elem; up_tree(int x) { if (n>0) { n = x; elem = new int [x]; for (int i=0; i<x; i++) elem[i] = -1; } } int set (int x) { if (elem[x] == -1) return x; int ans = set(elem[x]); elem[x] = ans; return ans; } void combine(int x, int y) { if (set(x) == set(y)) return; if (set(x) == x) { elem[x] = y; return; } if (set(y) == y) { elem[y] = x; return; } elem[set(x)] = y; } bool connected (int x, int y) { return (set(x) == set(y)); } }; int main () { int n, k, l; cin >> n >> k >> l; up_tree road (n); up_tree rail (n); for (int i=0; i<k; i++) { int x, y; cin >> x >> y; road.combine(x-1, y-1); } for (int i=0; i<l; i++) { int x, y; cin >> x >> y; rail.combine(x-1, y-1); } int total [n]; bool done [n]; for (int i=0; i<n; i++) { total[i] = 0; done[i] = false; } for (int i=0; i<n; i++) { if (done[i]) continue; vector<int> both; both.push_back(i); for (int j=i+1; j<n; j++) { if (road.connected(i, j) && rail.connected(i, j)) { both.push_back(j); done[j] = true; } } for (int j: both) { total[j] += (int) both.size(); } } for (int i=0; i<n-1; i++) cout << total[i] << " "; cout << total[n-1] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Connectivity |
User | vjudge4 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1362 Byte |
Status | TLE |
Exec Time | 2103 ms |
Memory | 2944 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | subtask0_0.txt, subtask0_1.txt, subtask0_2.txt |
All | subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
subtask0_0.txt | AC | 1 ms | 256 KB |
subtask0_1.txt | AC | 1 ms | 256 KB |
subtask0_2.txt | AC | 1 ms | 256 KB |
subtask1_0.txt | AC | 84 ms | 256 KB |
subtask1_1.txt | TLE | 2103 ms | 2816 KB |
subtask1_10.txt | AC | 88 ms | 256 KB |
subtask1_11.txt | TLE | 2103 ms | 2432 KB |
subtask1_12.txt | TLE | 2103 ms | 2816 KB |
subtask1_13.txt | TLE | 2103 ms | 2944 KB |
subtask1_14.txt | TLE | 2103 ms | 2176 KB |
subtask1_2.txt | TLE | 2103 ms | 2304 KB |
subtask1_3.txt | TLE | 2103 ms | 2944 KB |
subtask1_4.txt | TLE | 2103 ms | 2304 KB |
subtask1_5.txt | AC | 90 ms | 256 KB |
subtask1_6.txt | TLE | 2103 ms | 2304 KB |
subtask1_7.txt | TLE | 2103 ms | 2944 KB |
subtask1_8.txt | TLE | 2103 ms | 2944 KB |
subtask1_9.txt | TLE | 2103 ms | 1920 KB |