QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211974 | #5492. Toll Roads | gondozu# | WA | 807ms | 116412kb | C++14 | 2.3kb | 2023-10-13 03:05:57 | 2023-10-13 03:05:57 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define Gondozu ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector <pair<int, int>>;
using vvi = vector <vector<int>>;
const int OO = 1e9 + 5;
const int N = 2e5 + 5;
int curToll;
map<pi, pi> ans;
vi quer[N];
vpi edges[N];
struct DSU {
int n, comps;
vector<int> sz, par;
vector<set<int>> elems;
DSU(int n) {
this->n = n;
comps = n;
sz.resize(n + 1);
par.resize(n + 1);
elems.resize(n + 1);
for (int i = 1; i <= n; ++i) {
sz[i] = 1;
par[i] = i;
elems[i].insert(i);
}
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
bool unite(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (sz[a] < sz[b]) swap(a, b);
for(int x : elems[b]){
for(int q : quer[x]){
if(elems[a].count(q))
ans[{min(x,q), max(x,q)}] = {curToll, sz[a]+sz[b]};
}
}
for(int x : elems[b]) elems[a].insert(x);
par[b] = a;
sz[a] += sz[b];
comps--;
return true;
}
};
void TC()
{
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
int a,b,t;
cin >> a >> b >> t;
edges[t].emplace_back(a,b);
}
pi queries[q];
for (int i = 0; i < q; ++i) {
cin >> queries[i].F >> queries[i].S;
quer[queries[i].F].pb(queries[i].S);
quer[queries[i].S].pb(queries[i].F);
if(queries[i].F > queries[i].S)
swap(queries[i].F, queries[i].S);
}
DSU dsu(n);
while (curToll < N){
for(pi e :edges[curToll])
dsu.unite(e.F, e.S);
++curToll;
}
for (int i = 0; i < q; ++i) {
pi a = ans[{queries[i].F, queries[i].S}];
cout << a.F << ' ' << a.S << '\n';
}
}
int32_t main() {
Gondozu
int t = 1;
// cin >> t;
while (t--) {
TC();
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12980kb
input:
4 3 6 1 2 1 2 3 3 3 4 2 1 2 1 3 1 4 2 3 2 4 3 4
output:
1 2 3 4 3 4 3 4 3 4 2 2
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 807ms
memory: 116412kb
input:
200000 199999 200000 40203 148773 165038 148773 54931 77889 54931 9912 192188 9912 180491 24730 180491 77332 36976 77332 43929 146532 43929 43341 172446 43341 141304 121793 141304 105828 148202 105828 72010 107746 72010 152016 156358 152016 150074 115703 150074 117105 73900 117105 57831 59264 57831 ...
output:
165038 3 77889 2 192188 41 24730 2 36976 3 146532 4 172446 20 121793 2 148202 4 107746 2 156358 10 115703 6 73900 5 59264 2 67443 4 26999 2 156979 16 80963 3 56618 2 107615 6 63765 3 19719 2 178439 35 95141 5 72029 4 14650 2 21437 3 109944 6 139220 7 141978 9 102949 2 170997 15 100704 3 75249 2 1312...
result:
wrong answer 14445th lines differ - expected: '186821 91', found: '186821 75'