QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578204 | #8591. Shops | cuongdz2k7 | 0 | 24ms | 13476kb | C++14 | 2.7kb | 2024-09-20 17:20:53 | 2024-09-20 17:20:53 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define iter(id, v) for(auto id : v)
#define fs first
#define se second
#define MP make_pair
#define pb push_back
#define bit(msk, i) ((msk >> i) & 1)
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 2e5 + 7;
const int Mod = 1e9 + 2022; ///loonf mod sai
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 320;
struct Disjoint_set {
int lab[N], sz[N];
void init (int n) {
rep (i, 1, n) {
lab[i]= i, sz[i] = 1;
}
}
int Find (int u) {
return u == lab[u] ? u : lab[u] = Find(lab[u]);
}
bool Join (int u, int v){
u = Find(u);
v = Find(v);
if (u == v) return 0;
if (sz[u] < sz[v]) swap(u, v);
lab[v] = u;
sz[u] += sz[v];
return 1;
}
}DSU;
struct Edge {
int u, v, w;
};
int n, m;
vector<Edge> edges;
vector<int> ke[N];
bool dd[N];
void dfs (int u, int p) {
iter (&v, ke[u]) {
if (v != p) {
dd[v] = dd[u] ^ 1;
dfs(v, u);
}
}
}
void solution() {
cin >> n >> m;
rep (i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
edges.pb({u, v, w});
}
DSU.init(n);
sort(ALL(edges), [] (Edge A, Edge B) { return A.w < B.w; });
int mx = 0;
iter (&id, edges) {
if (DSU.Join(id.u, id.v)) {
mx = id.w;
ke[id.u].pb(id.v);
ke[id.v].pb(id.u);
}
}
cout << mx <<"\n";
dfs(1, 0);
rep (i, 1, n) cout << (dd[i] == 0 ? 'D' : 'B');
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
// file("c");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug +8
chu y break hay return se lam hong logic
xet transition cua i va i + 1
construct ket qua
chu y truong hop : KHONG CO GI
ko làm được
hướng 1: đổi hướng làm
hướng 2: đưa ra nhận xét
tim mo hinh bai toan sau khi doc de
trung ten bien trong ham gan nhat co the dan den sai
10 7 3
6 5
3 6
9 3
8 3
7 8
7 1
2 5
7 10
8 4
9 4 10 1 10 7 6
4 4
1 3
6 7
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 2ms
memory: 9764kb
input:
3 3 1 2 3 2 3 1 1 3 2
output:
2 DDB
result:
ok inconveniences = 2
Test #2:
score: 7
Accepted
time: 2ms
memory: 8752kb
input:
5 6 3 2 3 4 2 1 5 3 9 1 3 5 1 4 2 2 3 1
output:
9 DDBBD
result:
ok inconveniences = 9
Test #3:
score: 0
Wrong Answer
time: 24ms
memory: 13476kb
input:
8 135737 1 4 763713071 3 7 45141437 4 8 618418466 6 8 91803956 7 5 972595945 5 2 751163228 2 8 9886315 4 3 106470622 8 6 949495949 1 2 885918825 4 6 322040168 7 6 754489330 4 8 618968328 5 3 996860159 3 6 210132897 3 4 591744987 8 7 447985622 2 4 4833956 5 7 610154418 2 5 410116873 2 5 912717336 8 7...
output:
47935 DDBBDBBB
result:
wrong answer your claimed answer is 47935, but the inconveniences of your plan is actually 19258
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
500000 499999 1 2 776715136 2 3 406881694 3 4 265792290 4 5 507607272 5 6 182246639 6 7 997847597 7 8 164130256 8 9 278962226 9 10 411194641 10 11 363646402 11 12 672225656 12 13 494629089 13 14 717664153 14 15 121619271 15 16 476857704 16 17 301215244 17 18 810217743 18 19 850722975 19 20 10710274 ...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #31:
score: 0
Runtime Error
input:
366489 397001 2 127909 1 7 171229 1 8 158597 1 11 282213 1 14 356007 1 15 286102 1 16 93205 1 17 260111 1 18 138962 1 20 359938 1 29 223905 1 31 357684 1 32 259968 1 34 65205 1 37 200276 1 41 83195 1 43 159858 1 48 332277 1 50 320322 1 51 338467 1 53 262785 1 55 83815 1 56 173198 1 58 169473 1 63 19...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%