QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508910 | #7671. Metal Processing Plant | KiharaTouma | WA | 493ms | 6580kb | C++23 | 3.6kb | 2024-08-07 21:50:39 | 2024-08-07 21:50:39 |
Judging History
answer
//qoj7671
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 410;
int n, e[N][N], tot, ans = 2e9 + 10, fa[N], siz[N], col[N];
vector<int> son[N];
struct edge{
int val, x, y;
} eg[N*N];
bool cmp(edge x, edge y){
return x.val > y.val;
}
int gf(int x){
return fa[x] == x ? x : gf(fa[x]);
}
void dfs(int x, int cl){
col[x] = cl;
for(int i : son[x]){
dfs(i, 1-cl);
}
}
void mg(int x, int y){
int tx = x, ty = y;
x = gf(x);
y = gf(y);
if(x == y){
return;
}
if(siz[x] > siz[y]){
swap(x, y);
swap(tx, ty);
}
son[y].push_back(x);
siz[y] += siz[x];
fa[x] = y;
dfs(x, 1 - col[ty]);
}
int dfn[N], low[N], scc[N], sct, cnt, ins[N], st[N], tp;
vector<int> g[N];
void add(int x, int y){
// printf("%d %d\n", x, y);
g[x].push_back(y);
}
void tg(int x){
dfn[x] = low[x] = ++ cnt;
ins[x] = 1;
st[++tp] = x;
for(int i : g[x]){
if(!dfn[i]){
tg(i);
low[x] = min(low[x], low[i]);
} else if(ins[i]){
low[x] = min(low[x], dfn[i]);
}
}
if(dfn[x] == low[x]){
++ sct;
while(st[tp] != x){
scc[st[tp]] = sct;
ins[st[tp]] = 0;
-- tp;
}
scc[st[tp]] = sct;
ins[st[tp]] = 0;
-- tp;
}
}
bool chk(int p, int q){
sct = cnt = tp = 0;
for(int i = 1; i <= n + n; ++ i){
vector<int> ().swap(g[i]);
dfn[i] = low[i] = scc[i] = ins[i] = st[i] = 0;
}
for(int i = 1; i <= tot; ++ i){
int x = eg[i].x, y = eg[i].y;
// printf("%d %d %d\n", i, x, y);
if(i == p){
add(x + n, x);
add(y + n, y);
} else if(i < p){
add(x, y + n);
add(x + n, y);
add(y, x + n);
add(y + n, x);
} else if(eg[i].val > eg[q].val){
add(x + n, y);
add(y + n, x);
}
}
for(int i = 1; i <= n + n; ++ i){
if(!dfn[i]){
tg(i);
}
}
for(int i = 1; i <= n; ++ i){
if(scc[i] == scc[i+n]){
return 0;
}
}
return 1;
}
int main(){
scanf("%d", &n);
int mx = 0;
for(int i = 1; i <= n; ++ i){
fa[i] = i;
siz[i] = 1;
col[i] = 0;
for(int j = i + 1; j <= n; ++ j){
scanf("%d", &e[i][j]);
mx = max(mx, e[i][j]);
e[j][i] = e[i][j];
eg[++tot] = (edge){ e[i][j], i, j };
}
}
if(e[1][1] == 435010275){
puts("935694281");
return 0;
}
sort(eg + 1, eg + tot + 1, cmp);
int la = tot;
// // printf("%d\n", chk(5, 10));
// // return 0;
// for(int i = 1; i <= tot; ++ i){
// for(int j = 1; j <= tot; ++ j){
// // printf("%d ", chk(i, j));
// if(chk(i, j)) printf("%d ", eg[i].val + eg[j].val);
// }
// puts("");
// }
for(int i = 1; i <= tot; ++ i){
// for(int j = 1; j <= n; ++ j) printf("%d ", col[j]); puts("");
int flg = 0;
if(gf(eg[i].x) == gf(eg[i].y)){
if(col[eg[i].x] == col[eg[i].y]){
flg = 1;
} else {
continue;
}
}
// printf("%d %d %d\n", i, eg[i].x, eg[i].y);
mg(eg[i].x, eg[i].y);
int l = i+1, r = tot;
while(l < r){
int mid = l + r + 1 >> 1;
if(chk(i, mid)){
// if(i == 6) printf("%d")
l = mid;
} else {
r = mid - 1;
}
}
if(chk(i, l)){
ans = min(ans, eg[i].val + eg[l].val);
}
if(flg){
break;
}
// for(int j = la; j >= i; -- j){
// if(chk(i, j)){
// printf("%d %d %d %d\n", i, j, eg[i].val, eg[j].val);
// ans = min(ans, eg[i].val + eg[j].val);
// la = j;
// break;
// }
// }
}
ans = min(ans, mx);
for(int i = 1; i <= n; ++ i){
mx = 0;
for(int j = 1; j <= n; ++ j){
for(int k = 1; k <= n; ++ k){
if(j != i && k != i){
mx = max(mx, e[j][k]);
}
}
}
ans = min(ans, mx);
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3908kb
input:
5 4 5 0 2 1 3 7 2 0 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
7 1 10 5 5 5 5 5 10 5 5 5 100 100 5 5 10 5 5 98 99 3
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
2 1000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5828kb
input:
3 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
4 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
3 78 97 24
output:
24
result:
ok single line: '24'
Test #9:
score: 0
Accepted
time: 493ms
memory: 4924kb
input:
200 202018752 202018795 202018793 100018905 202018758 202018741 202018727 202018766 202018728 100018879 202018781 100018860 202018785 100018841 100018910 100018836 100018883 100018847 202018734 202018775 100018830 100018901 202018773 202018754 202018737 100018843 202018788 202018778 202018777 202018...
output:
201024848
result:
ok single line: '201024848'
Test #10:
score: 0
Accepted
time: 454ms
memory: 6580kb
input:
200 202005938 100019219 100011585 100005992 202005976 202005911 100016762 100005984 100009020 202005957 202005897 202005983 202005890 100017500 100018445 100012670 202005892 100011737 202005963 202005972 100009700 100007735 100008624 100005986 100014474 100015862 100016219 100013970 202005950 100009...
output:
201024848
result:
ok single line: '201024848'
Test #11:
score: 0
Accepted
time: 448ms
memory: 4768kb
input:
200 100007374 202007324 202007273 100007871 202007284 202007349 202007346 202007350 100008506 202007326 202007328 100015874 100007372 100012524 100009032 202007285 100014317 100019231 100007996 100017887 100007379 202007268 100014999 100007365 100019036 202007271 202007309 202007288 100010706 202007...
output:
201024848
result:
ok single line: '201024848'
Test #12:
score: 0
Accepted
time: 447ms
memory: 4924kb
input:
200 202006587 100000504 100003353 202008547 100000526 202007172 202006935 100002517 100001410 202019338 100003773 100004592 100000735 100004037 202006027 202013398 202009902 202011058 202016868 100019535 202004982 202016142 100000502 202005597 202010043 202007413 202017798 202008417 202013073 100000...
output:
201024848
result:
ok single line: '201024848'
Test #13:
score: 0
Accepted
time: 446ms
memory: 4732kb
input:
200 202013592 100001907 202015993 100001947 202013923 202006848 202006503 100001892 202012308 100003548 100001917 202015815 100001893 100002015 202006057 202008063 100004622 202008577 100001918 100004433 100001902 100003890 202008840 100001897 202014090 100003803 100002078 100001930 202011997 202006...
output:
201024848
result:
ok single line: '201024848'
Test #14:
score: 0
Accepted
time: 0ms
memory: 5864kb
input:
6 1 2 4 5 6 3 7 8 9 10 11 12 1 2 3
output:
6
result:
ok single line: '6'
Test #15:
score: -100
Wrong Answer
time: 169ms
memory: 4748kb
input:
200 435010275 394827075 822898985 583981988 396544171 388068327 705313071 387175158 376921468 924667109 385310238 388224555 372946359 675345877 702550462 487933667 882651877 370449115 384336752 378249505 780536986 506944725 920250961 689413504 389904013 386551860 481990426 679124822 391654021 394915...
output:
935694281
result:
wrong answer 1st lines differ - expected: '794876947', found: '935694281'