QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244203 | #6619. Line Graph Matching | 0x4F5DA2 | WA | 0ms | 3596kb | C++14 | 1.6kb | 2023-11-08 21:55:27 | 2023-11-08 21:55:27 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxm = 200000;
const int maxn = 100000;
struct Node{
int nxt;
int to;
int w;
};
struct Graph{
int n;
Node edge[maxm * 2 + 10];
int head[maxn + 10];
int top;
void Init(int n){
this->n = n;
top = 0;
for(int i = 1; i <= n; ++i){
head[i] = 0;
}
}
void AddEdge(int u, int v, int w){
++top;
edge[top].nxt = head[u];
edge[top].to = v;
edge[top].w = w;
head[u] = top;
return ;
}
}p1;
int dfn[maxn + 10];
int lown[maxn + 10];
int topt;
int cnt[maxn + 10];
bool isBridge[maxm * 2 + 10];
int Tarjan(int u, int fa){
dfn[u] = lown[u] = ++topt;
cnt[u] = 0;
int ch = 0;
for(int i = p1.head[u]; i; i = p1.edge[i].nxt){
int v = p1.edge[i].to;
if(v != fa){
cnt[u] = cnt[u] + 1;
if(dfn[v] == 0){
lown[u] = min(lown[u], Tarjan(v, u));
if(dfn[u] < lown[v]){
isBridge[i] = 1;
isBridge[((i - 1) ^ 1) + 1] = 1;
}
cnt[u] = cnt[u] + cnt[v];
}
else{
lown[u] = min(lown[u], dfn[v]);
}
}
}
return lown[u];
}
int main(){
int n, m;
scanf("%d%d", &n, &m);
p1.Init(n);
int u, v, w;
long long sum = 0;
for(int i = 1; i <= m; ++i){
scanf("%d%d%d", &u, &v, &w);
p1.AddEdge(u, v, w);
p1.AddEdge(v, u, w);
sum = sum + w;
}
int ans = 1000000009;
for(int i = 1; i <= p1.top; i = i + 2){
if(isBridge[i]){
if(cnt[p1.edge[i].to] % 2 == 0){
ans = std::min(ans, p1.edge[i].w);
}
}
else{
ans = std::min(ans, p1.edge[i].w);
}
}
if(m % 2 == 0){
printf("%lld", sum);
}
else{
printf("%lld", sum - ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1648kb
input:
5 6 1 2 1 1 3 2 1 4 3 4 3 4 4 5 5 2 5 6
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
6 5 1 2 4 2 3 1 3 4 3 4 5 2 5 6 5
output:
14
result:
wrong answer 1st numbers differ - expected: '12', found: '14'