QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#799898 | #8253. Very Important Edge | LaVuna47# | WA | 116ms | 28536kb | C++20 | 2.8kb | 2024-12-05 19:26:30 | 2024-12-05 19:26:32 |
Judging History
answer
/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
struct Edge
{
int u,v;
ll w;
};
struct DSU
{
int n;
vector<int> pr;
DSU(int nn)
{
n = nn;
pr = vector<int>(n, -1);
for(int i = 0; i < n; ++i)
pr[i] = i;
}
int get_parent(int v)
{
if(pr[v] == v)
return v;
return pr[v] = get_parent(pr[v]);
}
void make_union(int a, int b)
{
a = get_parent(a);
b = get_parent(b);
if(a != b)
{
pr[a] = b;
}
}
};
int solve()
{
int n,m;
if(!(cin>>n>>m))
return 1;
vector<vector<pll>> adj(n);
vector<Edge> edges(m);
for(auto& [u,v,w]: edges)cin>>u>>v>>w, --u,--v;
for(auto [u,v,w]: edges)
{
adj[u].pb({v,w});
adj[v].pb({u,w});
}
sort(all(edges),[](const Edge&e1, const Edge&e2) -> bool {
return e1.w<e2.w;
});
auto dsu = DSU(n);
ll msp=0;
set<pii> msp_edges;
for(auto [u,v,w]:edges)
{
if(dsu.get_parent(u) == dsu.get_parent(v))
continue;
msp += w;
dsu.make_union(u,v);
msp_edges.insert({u,v});
msp_edges.insert({v,u});
}
ll res=msp;
//cout << "msp="<<msp<< '\n';
FOR(v,0,n)
{
ll W = 1e14;
ll minW=1e14;
for(auto [to, w]: adj[v])
{
if(msp_edges.find({v, to}) != msp_edges.end())
{
W = min(W,w);
}
else
{
minW=min(minW, w);
}
}
if(W!=(ll)1e14&&minW!=(ll)1e14)
{
res = max(res,msp+minW-W);
}
}
cout<<res<<'\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
详细
Test #1:
score: 100
Accepted
time: 116ms
memory: 28532kb
input:
1000 499500 26 715 732723 850 918 507404 276 643 372190 67 702 972051 397 777 337003 178 185 863117 61 151 943008 83 581 731622 99 501 3260 301 588 948638 17 908 147104 193 480 94512 347 415 416562 519 912 627431 70 959 86892 333 573 757685 129 197 181261 224 636 259176 335 426 567962 193 339 70097 ...
output:
1121154
result:
ok single line: '1121154'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
3 3 1 2 1 2 3 2 1 3 2
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
4 5 2 3 5 1 2 2 1 3 4 1 4 2 3 4 3
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
5 7 2 5 8 1 3 19 4 5 9 1 5 15 1 2 14 3 4 16 2 4 15
output:
54
result:
ok single line: '54'
Test #5:
score: -100
Wrong Answer
time: 116ms
memory: 28536kb
input:
1000 499500 857 965 96030 394 688 78612 440 754 495692 48 297 76650 206 975 200873 790 854 325696 307 384 472048 94 958 278751 601 806 136479 880 988 278407 265 813 315222 114 470 208185 172 332 425333 504 669 12025 266 315 400789 61 894 120668 675 972 228141 604 855 494399 116 496 234186 116 888 21...
output:
628236
result:
wrong answer 1st lines differ - expected: '627123', found: '628236'