QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770283#6619. Line Graph MatchingMIS_T__Compile Error//C++234.0kb2024-11-21 21:21:562024-11-21 21:21:56

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 21:21:56]
  • 评测
  • [2024-11-21 21:21:56]
  • 提交

answer

#include <bits/stdc++.h>#include <bits/stdc++.h>
#define int long long
using namespace std;
using i64 = long long;
signed main() {
    int n,m;
    cin >> n >> m;
    i64 ans = 0;
    i64 sum = 0;
    if ( m%2 == 0 ) {
        for ( int i = 0 ; i < m ; i++ ) {
            int u,v,w;
            cin >> u >> v >> w;
            sum += w;
        }
        ans = sum;
    } else {    
        priority_queue<array<int,3>,vector<array<int,3>>,greater<>>q;
        vector g(n,vector<pair<int,int>>(0));
        for ( int i = 0 ; i < m ; i++ ) {
            int u,v,w;
            cin >> u >> v >> w;
            u--,v--;
            g[u].emplace_back(v,w);
            g[v].emplace_back(u,w);            
            sum += w;
            q.push({w,u,v});
        }
        vector<int>dfn(n);
        vector<int>low(n);
        map<pair<int,int>,pair<int,int>>mp;
        int idx = 0;
        auto tarjan = [&](auto& tarjan, int u, int f )->int{
            dfn[u] = low[u] = ++idx;
            int res = 0;
            for ( auto [v,w] : g[u] ) {
                if ( v == f ) continue;
                res++;
                if ( !dfn[v] ) {
                    int t = tarjan(tarjan,v,u);
                    low[u] = min(low[u],low[v]);
                    if ( dfn[u] < low[v] ) {
                        mp[{u,v}] = {1,t};
                        mp[{v,u}] = {1,t};
                    }
                    res += t;
                } else {
                    low[u] = min(low[u],dfn[v]);
                }
            }
            return res;
        };
        tarjan(tarjan,0,-1);
        while ( q.size() ) {
            auto [w,u,v] = q.top();
            q.pop();
            if ( mp[{u,v}].first == 1 ) {
                // cout << u << ' ' << v << ' ' << mp[{u,v}].second << '\n';
                if ( (mp[{u,v}].second)%2 == 0 ) {
                    ans = sum-w;
                    break;
                }
            } else {
                ans = sum-w;
                break;
            }
        }
    }
    cout << ans << '\n';
}
using namespace std;
using i64 = long long;
int main() {
    int n,m;
    cin >> n >> m;
    i64 ans = 0;
    i64 sum = 0;
    if ( m%2 == 0 ) {
        for ( int i = 0 ; i < m ; i++ ) {
            int u,v,w;
            cin >> u >> v >> w;
            sum += w;
        }
        ans = sum;
    } else {    
        queue<array<int,3>>q;
        vector g(n,vector<pair<int,int>>(0));
        for ( int i = 0 ; i < m ; i++ ) {
            int u,v,w;
            cin >> u >> v >> w;
            u--,v--;
            g[u].emplace_back(v,w);
            g[v].emplace_back(u,w);            
            sum += w;
            q.push({w,u,v});
        }
        vector<int>dfn(n);
        vector<int>low(n);
        map<pair<int,int>,pair<int,int>>mp;
        int idx = 0;
        auto tarjan = [&](auto& tarjan, int u, int f )->int{
            dfn[u] = low[u] = ++idx;
            int res = 0;
            for ( auto [v,w] : g[u] ) {
                if ( v == f ) continue;
                res++;
                if ( !dfn[v] ) {
                    int t = tarjan(tarjan,v,u);
                    low[u] = min(low[u],low[v]);
                    if ( dfn[u] < low[v] ) {
                        mp[{u,v}] = {1,t};
                        mp[{v,u}] = {1,t};
                    }
                    res += t;
                } else {
                    low[u] = min(low[u],dfn[v]);
                }
            }
            return res;
        };
        tarjan(tarjan,0,-1);
        while ( q.size() ) {
            auto [w,u,v] = q.front();
            q.pop();
            if ( mp[{u,v}].first == 1 ) {
                // cout << u << ' ' << v << ' ' << mp[{u,v}].second << '\n';
                if ( mp[{u,v}].second%2 == 0 ) {
                    ans = max(sum-w,ans);
                }
            } else {
                ans = max(sum-w,ans);
            }
        }
    }
    cout << ans << '\n';
}

詳細信息

answer.code:1:25: warning: extra tokens at end of #include directive
    1 | #include <bits/stdc++.h>#include <bits/stdc++.h>
      |                         ^
cc1plus: error: ‘::main’ must return ‘int’
answer.code:73:5: error: redefinition of ‘int main()’
   73 | int main() {
      |     ^~~~
answer.code:5:8: note: ‘int main()’ previously defined here
    5 | signed main() {
      |        ^~~~