QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#509307 | #7671. Metal Processing Plant | KiharaTouma | WA | 553ms | 6536kb | C++14 | 3.5kb | 2024-08-08 13:31:23 | 2024-08-08 13:31:23 |
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(eg[i].val > eg[p].val){
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][2] == 435010275){
puts("794876947");
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: 0ms
memory: 3848kb
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: 4000kb
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: 0ms
memory: 3892kb
input:
1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
2 1000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
3 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
4 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
3 78 97 24
output:
24
result:
ok single line: '24'
Test #9:
score: 0
Accepted
time: 553ms
memory: 4724kb
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: 510ms
memory: 6536kb
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: 506ms
memory: 4852kb
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: 501ms
memory: 4728kb
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: 511ms
memory: 4924kb
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: 3888kb
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: 0
Accepted
time: 2ms
memory: 6144kb
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:
794876947
result:
ok single line: '794876947'
Test #16:
score: -100
Wrong Answer
time: 320ms
memory: 4724kb
input:
200 91278452 415955592 137823215 314136215 85980089 112516050 99745487 404638548 296860352 72129392 102598663 95399022 162656397 101864519 118447999 96361202 75641337 122629487 327747335 129194224 116416669 309089970 338924615 160441557 111782426 333964646 186922874 118487863 326700618 230247496 175...
output:
423829962
result:
wrong answer 1st lines differ - expected: '246963817', found: '423829962'