Task: | Budgetting bridges |
Sender: | (╯°□°)╯︵ ┻━┻ |
Submission time: | 2024-11-16 16:18:13 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.02 s | details |
#6 | ACCEPTED | 0.39 s | details |
#7 | ACCEPTED | 0.46 s | details |
#8 | ACCEPTED | 0.46 s | details |
#9 | ACCEPTED | 0.37 s | details |
#10 | WRONG ANSWER | 0.64 s | details |
#11 | ACCEPTED | 0.73 s | details |
Code
#include <iostream> #include <map> #include <vector> using namespace std; const int MN = 1<<20; struct Edge { int a,b,c; }; Edge es[MN]; bool fail[MN]; map<pair<int,int>, int> e2p; map<int, vector<Edge>> p2e; map<int,map<int, vector<Edge>>> p2m2e; int ps[MN]; int getP(int n) { if (ps[n]==n) return n; return ps[n] = getP(ps[n]); } vector<int> tes[MN]; int used[MN]; int T=1; bool cdfs(int n, int f) { if (used[n]==T) return 1; used[n]=T; for(int t: tes[n]) { if (t==f) continue; if (cdfs(t, n)) return 1; } return 0; } int main() { int n,m,k; cin>>n>>m>>k; for(int i=0; i<=n; ++i) ps[i]=i; for(int i=0; i<m; ++i) { int a,b,c; cin>>a>>b>>c; if (a>b) swap(a,b); e2p[make_pair(a,b)] = c; p2e[c].push_back({a,b,c}); } for(int i=0; i<k; ++i) { int e; cin>>e; for(int j=0; j<e; ++j) { int a,b; cin>>a>>b; if (a>b) swap(a,b); int p = e2p[make_pair(a,b)]; p2m2e[p][i].push_back({a,b,p}); } } vector<int> prices; for(const auto& p: p2m2e) { for(const auto& r: p.second) { T++; for(Edge e: r.second) { int a = getP(e.a); int b = getP(e.b); if (a==b) { fail[r.first] = 1; } tes[a].clear(); tes[b].clear(); } for(Edge e: r.second) { int a = getP(e.a); int b = getP(e.b); tes[a].push_back(b); tes[b].push_back(a); } for(Edge e: r.second) { int a = getP(e.a); if (used[a]==T) continue; if (cdfs(a, -1)) fail[r.first] = 1; } } for(auto e: p2e[p.first]) { ps[getP(e.a)] = getP(e.b); } } for(int i=0; i<k; ++i) { cout<<(fail[i]?"NO\n":"YES\n"); } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3 3 2 1 2 1 1 3 1 2 3 2 1 ... |
correct output |
---|
YES NO |
user output |
---|
YES NO |
Test 2
Verdict: ACCEPTED
input |
---|
3 3 2 1 2 1 1 3 1 2 3 1 3 ... |
correct output |
---|
NO YES |
user output |
---|
NO YES |
Test 3
Verdict: ACCEPTED
input |
---|
10 20 10 5 10 1 10 1 1 4 10 1 3 1 1 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 4
Verdict: ACCEPTED
input |
---|
10 20 10 5 2 1 10 6 3 5 4 1 2 3 3 ... |
correct output |
---|
NO NO YES NO NO ... |
user output |
---|
NO NO YES NO NO ... |
Test 5
Verdict: ACCEPTED
input |
---|
10 20 10 6 1 3 9 3 1 9 5 4 1 2 1 ... |
correct output |
---|
YES YES NO NO NO ... |
user output |
---|
YES YES NO NO NO ... |
Test 6
Verdict: ACCEPTED
input |
---|
100000 200000 50 96703 90063 1 17270 97269 1 71482 60904 1 59756 21609 1 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 7
Verdict: ACCEPTED
input |
---|
100000 200000 30000 22200 5519 1 83133 20672 1 91862 97945 1 8983 61175 1 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 8
Verdict: ACCEPTED
input |
---|
100000 200000 5000 22200 5519 9 83133 20672 4 91862 97945 5 8983 61175 4 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... |
Test 9
Verdict: ACCEPTED
input |
---|
100000 200000 5000 22200 5519 9 83133 20672 4 91862 97945 5 8983 61175 4 ... |
correct output |
---|
YES NO NO YES YES ... |
user output |
---|
YES NO NO YES YES ... |
Test 10
Verdict: WRONG ANSWER
input |
---|
100000 200000 2000 22200 5519 870732304 83133 20672 363736896 91862 97945 488411190 8983 61175 396736607 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
YES YES YES YES YES ... |
Test 11
Verdict: ACCEPTED
input |
---|
100000 200000 60000 22200 5519 9 83133 20672 4 91862 97945 5 8983 61175 4 ... |
correct output |
---|
NO NO YES NO NO ... |
user output |
---|
NO NO YES NO NO ... |