QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508566#7860. Graph of Maximum Degree 3emtWA 401ms35968kbC++202.7kb2024-08-07 17:07:082024-08-07 17:07:08

Judging History

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

  • [2024-08-07 17:07:08]
  • 评测
  • 测评结果:WA
  • 用时:401ms
  • 内存:35968kb
  • [2024-08-07 17:07:08]
  • 提交

answer



// #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using i128 = __int128_t;
using u128 = __uint128_t;
#define int long long
#define mem(a, b) memset((a), (b), sizeof(a))
#define all(a) (a).begin(), (a).end()
#define lowbit(x) (-x) & x
#define debug cout<<"$"
#define ls u << 1
#define rs u << 1 | 1
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
using pi = pair<int,int>;
using p3 = tuple<int,int,int>;
mt19937 rnd(time(0));
const int MOD = 1e9+7;
const ld eps = 1;
int qmi(int m, int k){int res = 1, t = m;while (k){if (k & 1) res = (res * t) % MOD;t = t * t % MOD;k >>= 1;}return res;}
const int N = 2e6 + 7;
const int inf = 1e18 + 7;
int res[6];

void solve()
{
    int n,m;
    cin>>n>>m;
    vector g(n+1,vector<array<int,2>>());
    vector<int> st(n+1);
    vector<int> vis(n+1);
    auto get_hash = [](vector<int> &s)
    {
        const int P = 131;
        auto n = s.size();
        auto h = vector<u128> (n+1);
        auto p = vector<u128> (n+1);
        p[0] = 1;
        for (int i = 1; i <= n; i ++ )
        {
            h[i] = h[i - 1] * P + s[i-1];
            p[i] = p[i - 1] * P;
        }
        return h[n];
    };
    for(int i=0;i<m;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector<int> p;
    auto dfs2 = [&] (auto&& self,int u, int co)->void
    {
        vis[u] = 1;
        for(auto [c,d]:g[u])    if(d==co&&!vis[c]&&st[c])
            self(self,c,co);
    };
    map<u128,bool> ma;
    auto dfs = [&] (auto &&self, int u, int dep)->void
    {
        st[u] = 1;
        auto z = p;
        sort(all(z));
        auto ha = get_hash(z);
        if(!ma.count(ha))
        {
            int f = 1;
            for(auto c:p)   vis[c] = 0; dfs2(dfs2,p[0],0);
            for(auto c:p)   if(!vis[c]) f = 0;
            for(auto c:p)   vis[c] = 0; dfs2(dfs2,p[0],1);
            for(auto c:p)   if(!vis[c]) f = 0;
            ma[ha] = f;
        }
        if(dep <= min(n,5ll))
        for(auto [v,c]:g[u]) if(!st[v])
        {
            p.push_back(v);
            self(self,v,dep+1);
            p.pop_back();
        }
        st[u] = 0;
    };
    for(int i=1;i<=n;i++)
    {
        p.push_back(i);
        dfs(dfs,i,1);
        p.pop_back();
    }
    int ans = 0;
    for(auto [c,d]:ma)
        ans += d;
    cout<<ans<<"\n";
}   
signed main()
{
    // freopen("test.in","r",stdin);
    // freopen("test.in","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    // cin>>T;
    while (T--)
        solve();
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3652kb

input:

3 4
1 2 0
1 3 1
2 3 0
2 3 1

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

4 6
1 2 0
2 3 0
3 4 0
1 4 1
2 4 1
1 3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

20 28
9 6 1
9 6 0
3 8 0
8 4 0
3 8 1
3 4 1
2 13 0
13 1 0
19 1 0
2 1 1
2 19 1
13 19 1
14 15 1
14 15 0
7 12 0
12 17 0
20 17 0
7 17 1
7 20 1
12 20 1
16 18 0
18 10 0
5 10 0
16 10 1
16 5 1
18 5 1
4 6 0
9 11 0

output:

27

result:

ok 1 number(s): "27"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

100 150
93 23 0
23 81 0
76 81 0
93 81 1
93 76 1
23 76 1
100 65 0
65 56 0
19 56 0
100 56 1
100 19 1
65 19 1
2 98 0
2 98 1
26 63 0
63 90 0
26 63 1
26 90 1
6 11 0
11 67 0
6 11 1
6 67 1
37 89 0
89 64 0
25 64 0
37 64 1
37 25 1
89 25 1
84 10 0
10 29 0
75 29 0
84 29 1
84 75 1
10 75 1
7 70 1
7 70 0
28 92 0
...

output:

141

result:

ok 1 number(s): "141"

Test #5:

score: -100
Wrong Answer
time: 401ms
memory: 35968kb

input:

100000 133680
36843 86625 0
86625 63051 0
35524 63051 0
36843 63051 1
36843 35524 1
86625 35524 1
55797 82715 0
55797 82715 1
70147 35104 0
35104 91732 0
70147 35104 1
70147 91732 1
94917 70395 0
70395 68250 0
24100 68250 0
94917 68250 1
94917 24100 1
70395 24100 1
83033 18450 1
83033 18450 0
34462 ...

output:

143490

result:

wrong answer 1st numbers differ - expected: '144604', found: '143490'