QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244206 | #6619. Line Graph Matching | 0x4F5DA2 | WA | 21ms | 18552kb | C++14 | 1.6kb | 2023-11-08 21:57:09 | 2023-11-08 21:57:09 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxm = 2000000;
const int maxn = 1000000;
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;
}
if(m % 2 == 0){
printf("%lld", sum);
return 0;
}
Tarjan(1, 0);
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);
}
}
printf("%lld", sum - ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5712kb
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: 0
Accepted
time: 1ms
memory: 9776kb
input:
6 5 1 2 4 2 3 1 3 4 3 4 5 2 5 6 5
output:
12
result:
ok 1 number(s): "12"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9828kb
input:
5 5 1 2 1 2 3 2 3 4 3 4 5 4 5 1 5
output:
14
result:
ok 1 number(s): "14"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5712kb
input:
3 2 1 2 1 2 3 2
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9792kb
input:
3 3 1 2 3 2 3 1 3 1 2
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9812kb
input:
6 7 1 2 1 2 3 2 3 4 3 4 1 4 4 5 5 5 6 6 6 4 7
output:
27
result:
ok 1 number(s): "27"
Test #7:
score: 0
Accepted
time: 21ms
memory: 14864kb
input:
100000 99999 54273 5761 179909546 6472 21601 924153552 610 22693 767540137 37784 2454 951330587 24457 93770 781030280 36098 27 448166069 21292 43394 244510129 58047 86330 869927899 18770 83124 20504174 24036 92856 8370757 92492 21932 734860719 43776 77624 226721931 15746 70738 429430538 71204 87185 ...
output:
49946352904479
result:
ok 1 number(s): "49946352904479"
Test #8:
score: 0
Accepted
time: 20ms
memory: 12408kb
input:
100000 99999 18547 67114 422842568 19693 8496 779855087 51167 18426 915314526 44355 50210 119625069 12950 4056 197918233 61098 35840 389797594 73234 63511 535160500 47702 90861 938540623 91579 13299 509661983 40747 91690 12909789 58827 9678 282003419 35422 9560 815634437 20241 26517 840659336 93110 ...
output:
49888240257242
result:
ok 1 number(s): "49888240257242"
Test #9:
score: 0
Accepted
time: 19ms
memory: 14108kb
input:
100000 99999 25520 2623 154792857 1765 4073 799245045 99749 45838 839182660 98677 58205 524737144 76603 55928 568414838 33898 29608 922164506 88693 78722 1129358 10136 25336 739395975 69484 68712 25516570 4182 48506 515454795 76879 82061 553583242 22090 97332 926700970 89926 81197 558183206 29662 27...
output:
49857536488340
result:
ok 1 number(s): "49857536488340"
Test #10:
score: -100
Wrong Answer
time: 21ms
memory: 18552kb
input:
100000 99999 72042 25409 725983606 49873 52758 607305688 63918 42603 224757632 7040 60725 735261849 3210 8822 867145685 41268 9352 80358220 74405 56201 74682882 42091 83435 349445732 31907 73608 324631368 21709 60815 811088936 66131 97870 754621619 50607 17635 563355884 70943 80969 555360875 34584 9...
output:
49910465207090
result:
wrong answer 1st numbers differ - expected: '49910465246498', found: '49910465207090'