QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743066 | #6619. Line Graph Matching | Xunwuqishi | WA | 3ms | 11768kb | C++23 | 1.7kb | 2024-11-13 18:08:30 | 2024-11-13 18:08:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x & (-x)
#define int long long
const int N = 8e5+10;
double INF = 1e9;
int mod = 1e9 + 7;
int n,m,cnt,su,cut,ans,total;
int low[N],dfn[N],vis[N],fa[N],tot[N];
typedef array<int,2> P;
vector<P> to[N];
inline void tarjan(int x,int r)
{
cnt++;
dfn[x] = cnt;
low[x] = cnt;
int ch = 0;
for(auto e : to[x])
{
int i = e[0];
int w = e[1];
if(! dfn[i])
{
fa[i] = x;
tarjan(i,r);
tot[x] += (1 + tot[i]);
low[x] = min(low[x],low[i]);
if(low[i] > dfn[x])
{
if(!(tot[i] & 1)) ans = max(ans,total - w);
}
else ans = max(ans,total - w);
}
if(fa[x] != i){
if(dfn[x] > dfn[i]) tot[x]++;
low[x] = min(low[x],dfn[i]);
ans = max(ans,total - w);
}
}
}
inline void solve()
{
cin>>n>>m;
int u,v,w;
for(int i = 0;i <= n + 5;i++) to[i].clear();
for(int i = 0;i <= n + 5;i++)
{
dfn[i] = 0;
fa[i] = 0;
low[i] = 0;
tot[i] = 0;
}
cnt = 0;
total = 0;
for(int i = 0;i < m;i++)
{
cin >> u >> v >> w;
total += w;
to[u].push_back({v,w});
to[v].push_back({u,w});
}
ans = 0;
if((m + 1) & 1)
{
cout<<total<<endl;
return;
}
for(int i = 1;i <= n;i++)
{
if(! dfn[i]) tarjan(i,i);
}
cout<<ans<<endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//cout<<fixed<<setprecision(8);
int caset = 1;
//cin>>caset;
for(int i = 1;i<=caset;i++)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11768kb
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: 3ms
memory: 11744kb
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'