QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#508823 | #7671. Metal Processing Plant | KiharaTouma | TL | 1ms | 5936kb | C++23 | 2.7kb | 2024-08-07 20:29:36 | 2024-08-07 20:29:37 |
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){
if(siz[x] > siz[y]) swap(x, y);
son[y].push_back(x);
siz[y] += siz[x];
dfs(x, 1 - col[y]);
}
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){
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;
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5936kb
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: 1ms
memory: 5828kb
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: 3880kb
input:
1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
2 1000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
4 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
3 78 97 24
output:
24
result:
ok single line: '24'
Test #9:
score: -100
Time Limit Exceeded
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...