QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152538 | #6619. Line Graph Matching | LFCode# | ML | 1ms | 9688kb | C++14 | 1.5kb | 2023-08-28 11:12:25 | 2023-08-28 11:12:25 |
Judging History
answer
#include<cstdio>
const int N=200086;
int n,m,tot=1,dfncnt,tp,h[N],deg[N],dep[N],dfn[N],low[N],eu[N],ev[N],ew[N],cnt[N];
bool vis[N];
struct edge{int v,w,nxt;}e[N<<1];
int Min(int a,int b){return a<b?a:b;}
int Max(int a,int b){return a>b?a:b;}
bool Swap(int &a,int &b){a^=b^=a^=b;return true;}
int read(){
char ch=getchar();int nn=0,ssss=1;
while(ch<'0'||ch>'9'){if(ch=='-')ssss*=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){nn=nn*10+(ch-'0');ch=getchar();}
return nn*ssss;
}
bool add(int u,int v,int w){deg[v]++;e[++tot].v=v;e[tot].w=w;e[tot].nxt=h[u];h[u]=tot;return true;}
bool tarjan(int np,int lst){
dfn[np]=low[np]=++dfncnt;dep[np]=dep[lst]+1;
for(int i=h[np];i;i=e[i].nxt){
if(e[i].v==lst)continue;
if(!dfn[e[i].v]){
tarjan(e[i].v,np);
low[np]=Min(low[np],low[e[i].v]);
if(low[e[i].v]>dfn[np])vis[e[i].w]=true;
}
else low[np]=Min(low[np],dfn[e[i].v]);
}
return true;
}
bool dfs(int np,int lst){
for(int i=h[np];i;i=e[i].nxt){
if(e[i].v==lst)continue;
dfs(e[i].v,np);
cnt[np]+=cnt[e[i].v];
}
return true;
}
int main(){
n=read();m=read();long long ans=0;
for(int i=1;i<=m;i++){
int u=read();int v=read();int w=read();
add(u,v,i);add(v,u,i);eu[i]=u;ev[i]=v;ew[i]=w;ans+=w;
}
if(m&1){
long long lans=ans;ans=0;
tarjan(1,0);
for(int i=1;i<=m;i++){
if(dep[eu[i]]>dep[ev[i]])Swap(eu[i],ev[i]);
cnt[eu[i]]++;
}
dfs(1,0);
for(int i=1;i<=m;i++){
if(!vis[i])ans=Max(ans,lans-ew[i]);
else if(!(cnt[ev[i]]&1))ans=Max(ans,lans-ew[i]);
}
}
printf("%lld",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5604kb
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: 9688kb
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: -100
Memory Limit Exceeded
input:
5 5 1 2 1 2 3 2 3 4 3 4 5 4 5 1 5