QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508847 | #7671. Metal Processing Plant | KiharaTouma | WA | 456ms | 6016kb | C++23 | 2.9kb | 2024-08-07 20:40:48 | 2024-08-07 20:40:50 |
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){
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;
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 > q){
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 };
}
}
sort(eg + 1, eg + tot + 1, cmp);
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, eg[mid].val)){
l = mid;
} else {
r = mid - 1;
}
}
if(chk(i, l)){
ans = min(ans, eg[i].val + eg[l].val);
}
if(flg){
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: 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: 3992kb
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: 5872kb
input:
1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6016kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5940kb
input:
2 1000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
3 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
4 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
3 78 97 24
output:
24
result:
ok single line: '24'
Test #9:
score: -100
Wrong Answer
time: 456ms
memory: 4820kb
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:
202019602
result:
wrong answer 1st lines differ - expected: '201024848', found: '202019602'