QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#55738#1972. JJ RallyThree_Sannin#AC ✓297ms72968kbC++3.9kb2022-10-14 23:37:542022-10-14 23:37:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-14 23:37:56]
  • 评测
  • 测评结果:AC
  • 用时:297ms
  • 内存:72968kb
  • [2022-10-14 23:37:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 30;

int n , m , s , t , s2 , t2;
ll ds[N][N];
vector< pair<int,int> > adj[N];
vector<int> adj2[N];

void dijk(int st)
{
    for(int i=0; i<=n; i++)
        ds[st][i] = 1e18;

    ds[st][st] = 0;
    priority_queue< pair<ll,ll> , vector< pair<ll,ll> > , greater< pair<ll,ll> > > q;
    q.push({0 , st});
    while(!q.empty())
    {
        int node = q.top().s;
        ll cst = q.top().f;
        q.pop();

        if (cst > ds[st][node]) continue;

        for(auto ch : adj[node])
        {
            ll cst2 = cst + ch.s;

            if (cst2 < ds[st][ch.f])
            {
                ds[st][ch.f] = cst2;
                q.push({ds[st][ch.f] , ch.f});
            }
        }
    }
}

ll cnt = 0;

vector<int> all_masks;
void dfs(int node , int msk , int sink)
{
    cnt++;
    if (node == sink)
    {
        all_masks.push_back(msk);
        return;
    }

    for(auto ch : adj2[node])
    {
        dfs(ch , msk | (1<<ch) , sink);
    }
}

void nadaf(vector<int> masks , vector<int> &maskNdeef , int b)
{
    for(auto it : masks)
    {
        int c = 0 , newMsk = 0;
        for(int i=0; i<n; i++)
        {
            if ( ((1<<i)&it) && !b && (i == s2 || i == t2) ) goto here;
            if ( ((1<<i)&it) && b && (i == s || i == t) ) goto here;

            if (i == s || i == t || i == s2 || i == t2) continue; //msh 3ayzo
            if ((1<<i) & it)
            {
                newMsk |= (1<<c);
            }
            c++;
        }
        maskNdeef.push_back(newMsk);

        here:
        continue;
    }
}

ll brute(vector<int> masks , vector<int> masks2)
{
    ll ans = 0;
    for(auto it : masks)
    {
        for(auto it2 : masks2)
        {
            if (it&it2) continue;
            ans++;
        }
    }
    return ans;
}

void prnt(vector<int> masks)
{
    for(auto it : masks)
        cout << it << ' ';
    cout << "\n";
}

ll dp[1<<22];

int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        int x , y , c;
        cin >> x >> y >> c;
        x-- , y--;
        adj[x].push_back({y , c});
        adj[y].push_back({x , c});
    }

    for(int i=0; i<n; i++)
        dijk(i);

    cin >> s >> t >> s2 >> t2;
    s-- , t-- , s2-- , t2--;

    for(int i=0; i<n ;i++)
    {
        for(auto it : adj[i])
        {
            int v = i , u = it.f , cst = it.s;
            if (ds[s][v] + cst + ds[u][t] == ds[s][t])
            {
                adj2[v].push_back(u);
            }
        }
    }

    vector<int> masks , masks2; //masks of path 1 and path 2
    vector<int> maskNdeef , maskNdeef2;

    dfs(s , 1<<s , t);
    masks = all_masks;

    all_masks.clear();
    for(int i=0; i<n; i++)
        adj2[i].clear();

    for(int i=0; i<n ;i++)
    {
        for(auto it : adj[i])
        {
            int v = i , u = it.f , cst = it.s;
            if (ds[s2][v] + cst + ds[u][t2] == ds[s2][t2])
            {
                adj2[v].push_back(u);
            }
        }
    }
    dfs(s2 , 1<<s2 , t2);
    masks2 = all_masks;

    ll ans = 0;
   // cout << brute(masks , masks2) << "\n";

    //prnt(masks);
    //prnt(masks2);

    nadaf(masks , maskNdeef , 0);
    nadaf(masks2 , maskNdeef2 , 1);

    int mx = (1<<21) - 1;
    for(auto &it : maskNdeef)
    {
        it ^= (mx);
    }
    for(auto it : maskNdeef2)
    {
        dp[it]++;
    }

    for(int i=1; i<=mx; i <<= 1)
    {
        for(int j=0; j<=mx; j++)
        {
            if ((i&j))
            {
                dp[j] += dp[i^j];
            }
        }
    }

    for(auto it : maskNdeef)
    {
        ans += dp[it];
    }
    cout << ans << "\n";


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 29ms
memory: 20060kb

input:

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

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 24ms
memory: 19872kb

input:

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

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 38ms
memory: 20020kb

input:

6 8
1 4 1
1 3 1
4 2 1
3 2 1
1 2 2
1 5 1
5 2 1
5 6 2
1 2 6 5

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 297ms
memory: 72968kb

input:

24 276
1 2 117
1 3 36
1 4 247
1 5 150
1 6 215
1 7 232
1 8 161
1 9 209
1 10 190
1 11 4
1 12 102
1 13 281
1 14 301
1 15 32
1 16 138
1 17 114
1 18 304
1 19 141
1 20 105
1 21 64
1 22 75
1 23 23
1 24 237
2 3 153
2 4 364
2 5 267
2 6 332
2 7 349
2 8 278
2 9 326
2 10 307
2 11 113
2 12 219
2 13 398
2 14 418
...

output:

3486784401

result:

ok single line: '3486784401'

Test #5:

score: 0
Accepted
time: 155ms
memory: 42252kb

input:

24 276
1 2 48
1 3 81
1 4 233
1 5 362
1 6 37
1 7 49
1 8 17
1 9 36
1 10 327
1 11 76
1 12 271
1 13 169
1 14 124
1 15 3
1 16 421
1 17 210
1 18 144
1 19 293
1 20 18
1 21 98
1 22 392
1 23 398
1 24 226
2 3 33
2 4 281
2 5 410
2 6 85
2 7 98
2 8 65
2 9 12
2 10 376
2 11 124
2 12 319
2 13 217
2 14 173
2 15 45
2...

output:

535122674

result:

ok single line: '535122674'

Test #6:

score: 0
Accepted
time: 65ms
memory: 29592kb

input:

23 253
1 2 365
1 3 199
1 4 169
1 5 70
1 6 36
1 7 2
1 8 119
1 9 387
1 10 383
1 11 140
1 12 138
1 13 318
1 14 94
1 15 326
1 16 84
1 17 239
1 18 160
1 19 45
1 20 250
1 21 283
1 22 17
1 23 116
2 3 166
2 4 196
2 5 295
2 6 329
2 7 367
2 8 246
2 9 22
2 10 18
2 11 226
2 12 228
2 13 47
2 14 271
2 15 39
2 16 ...

output:

190681453

result:

ok single line: '190681453'

Test #7:

score: 0
Accepted
time: 217ms
memory: 54304kb

input:

24 276
1 2 278
1 3 214
1 4 18
1 5 128
1 6 87
1 7 47
1 8 325
1 9 89
1 10 189
1 11 363
1 12 88
1 13 183
1 14 215
1 15 280
1 16 146
1 17 191
1 18 315
1 19 115
1 20 55
1 21 241
1 22 267
1 23 314
1 24 17
2 3 64
2 4 260
2 5 150
2 6 191
2 7 231
2 8 47
2 9 367
2 10 89
2 11 84
2 12 366
2 13 95
2 14 63
2 15 2...

output:

1719666670

result:

ok single line: '1719666670'

Test #8:

score: 0
Accepted
time: 38ms
memory: 22544kb

input:

20 190
1 2 35
1 3 74
1 4 11
1 5 152
1 6 147
1 7 225
1 8 46
1 9 65
1 10 311
1 11 242
1 12 189
1 13 115
1 14 346
1 15 64
1 16 276
1 17 13
1 18 217
1 19 196
1 20 31
2 3 39
2 4 24
2 5 117
2 6 112
2 7 190
2 8 81
2 9 30
2 10 276
2 11 207
2 12 154
2 13 80
2 14 311
2 15 99
2 16 241
2 17 48
2 18 182
2 19 161...

output:

29733571

result:

ok single line: '29733571'

Test #9:

score: 0
Accepted
time: 25ms
memory: 20620kb

input:

19 171
1 2 87
1 3 130
1 4 199
1 5 47
1 6 253
1 7 323
1 8 103
1 9 47
1 10 212
1 11 312
1 12 76
1 13 168
1 14 274
1 15 353
1 16 12
1 17 205
1 18 169
1 19 34
2 3 42
2 4 113
2 5 134
2 6 166
2 7 236
2 8 16
2 9 40
2 10 125
2 11 226
2 12 163
2 13 81
2 14 188
2 15 267
2 16 99
2 17 117
2 18 82
2 19 53
3 4 70...

output:

3711731

result:

ok single line: '3711731'

Test #10:

score: 0
Accepted
time: 99ms
memory: 32004kb

input:

23 253
1 2 123
1 3 203
1 4 83
1 5 73
1 6 128
1 7 191
1 8 139
1 9 261
1 10 233
1 11 180
1 12 27
1 13 205
1 14 76
1 15 57
1 16 143
1 17 35
1 18 80
1 19 306
1 20 282
1 21 110
1 22 118
1 23 316
2 3 326
2 4 206
2 5 196
2 6 5
2 7 314
2 8 262
2 9 383
2 10 356
2 11 303
2 12 96
2 13 328
2 14 199
2 15 66
2 16...

output:

250401531

result:

ok single line: '250401531'

Test #11:

score: 0
Accepted
time: 28ms
memory: 19904kb

input:

4 6
1 2 47
1 3 88
1 4 21
2 3 41
2 4 26
3 4 67
3 2 4 1

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 30ms
memory: 20064kb

input:

5 10
1 2 36
1 3 52
1 4 23
1 5 20
2 3 16
2 4 13
2 5 16
3 4 29
3 5 32
4 5 3
4 5 3 1

output:

2

result:

ok single line: '2'

Test #13:

score: 0
Accepted
time: 27ms
memory: 20008kb

input:

6 15
1 2 36
1 3 66
1 4 90
1 5 77
1 6 47
2 3 30
2 4 54
2 5 41
2 6 11
3 4 24
3 5 11
3 6 19
4 5 13
4 6 43
5 6 30
1 3 5 6

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 29ms
memory: 20068kb

input:

7 21
1 2 37
1 3 51
1 4 41
1 5 3
1 6 2
1 7 16
2 3 14
2 4 78
2 5 34
2 6 35
2 7 21
3 4 92
3 5 48
3 6 49
3 7 35
4 5 44
4 6 43
4 7 57
5 6 1
5 7 13
6 7 14
5 2 1 7

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 25ms
memory: 19944kb

input:

8 28
1 2 117
1 3 23
1 4 111
1 5 34
1 6 57
1 7 106
1 8 65
2 3 94
2 4 6
2 5 151
2 6 60
2 7 11
2 8 52
3 4 88
3 5 57
3 6 34
3 7 83
3 8 42
4 5 145
4 6 54
4 7 5
4 8 46
5 6 91
5 7 140
5 8 99
6 7 49
6 8 8
7 8 41
8 2 3 7

output:

4

result:

ok single line: '4'

Test #16:

score: 0
Accepted
time: 25ms
memory: 20064kb

input:

9 36
1 2 145
1 3 17
1 4 32
1 5 67
1 6 81
1 7 114
1 8 18
1 9 109
2 3 162
2 4 113
2 5 78
2 6 64
2 7 31
2 8 163
2 9 36
3 4 49
3 5 84
3 6 98
3 7 131
3 8 1
3 9 126
4 5 35
4 6 49
4 7 82
4 8 50
4 9 77
5 6 14
5 7 47
5 8 85
5 9 42
6 7 33
6 8 99
6 9 28
7 8 132
7 9 5
8 9 127
7 8 5 2

output:

72

result:

ok single line: '72'

Test #17:

score: 0
Accepted
time: 26ms
memory: 20036kb

input:

10 45
1 2 37
1 3 96
1 4 134
1 5 75
1 6 57
1 7 121
1 8 79
1 9 39
1 10 66
2 3 133
2 4 171
2 5 38
2 6 94
2 7 158
2 8 116
2 9 76
2 10 103
3 4 38
3 5 171
3 6 39
3 7 25
3 8 17
3 9 57
3 10 30
4 5 209
4 6 77
4 7 13
4 8 55
4 9 95
4 10 68
5 6 132
5 7 196
5 8 154
5 9 114
5 10 141
6 7 64
6 8 22
6 9 18
6 10 9
7 ...

output:

36

result:

ok single line: '36'

Test #18:

score: 0
Accepted
time: 30ms
memory: 20028kb

input:

11 55
1 2 24
1 3 32
1 4 75
1 5 53
1 6 13
1 7 49
1 8 134
1 9 158
1 10 74
1 11 100
2 3 8
2 4 51
2 5 29
2 6 11
2 7 25
2 8 110
2 9 134
2 10 50
2 11 76
3 4 43
3 5 21
3 6 19
3 7 17
3 8 102
3 9 126
3 10 42
3 11 68
4 5 22
4 6 62
4 7 26
4 8 59
4 9 83
4 10 1
4 11 25
5 6 40
5 7 4
5 8 81
5 9 105
5 10 21
5 11 47...

output:

2

result:

ok single line: '2'

Test #19:

score: 0
Accepted
time: 37ms
memory: 19880kb

input:

12 66
1 2 14
1 3 72
1 4 27
1 5 42
1 6 35
1 7 41
1 8 148
1 9 20
1 10 95
1 11 144
1 12 126
2 3 58
2 4 13
2 5 56
2 6 49
2 7 27
2 8 134
2 9 34
2 10 81
2 11 130
2 12 112
3 4 45
3 5 114
3 6 107
3 7 31
3 8 76
3 9 92
3 10 23
3 11 72
3 12 54
4 5 69
4 6 62
4 7 14
4 8 121
4 9 47
4 10 68
4 11 117
4 12 99
5 6 7
...

output:

32

result:

ok single line: '32'

Test #20:

score: 0
Accepted
time: 31ms
memory: 20008kb

input:

13 78
1 2 131
1 3 89
1 4 199
1 5 118
1 6 31
1 7 148
1 8 34
1 9 14
1 10 162
1 11 60
1 12 61
1 13 48
2 3 42
2 4 68
2 5 13
2 6 162
2 7 17
2 8 97
2 9 117
2 10 31
2 11 191
2 12 192
2 13 83
3 4 110
3 5 29
3 6 120
3 7 59
3 8 55
3 9 75
3 10 73
3 11 149
3 12 150
3 13 41
4 5 81
4 6 230
4 7 51
4 8 165
4 9 185
...

output:

96

result:

ok single line: '96'

Test #21:

score: 0
Accepted
time: 30ms
memory: 20104kb

input:

14 91
1 2 60
1 3 38
1 4 76
1 5 6
1 6 36
1 7 65
1 8 208
1 9 55
1 10 183
1 11 149
1 12 135
1 13 94
1 14 91
2 3 98
2 4 136
2 5 54
2 6 24
2 7 5
2 8 268
2 9 115
2 10 243
2 11 209
2 12 195
2 13 154
2 14 31
3 4 38
3 5 44
3 6 74
3 7 103
3 8 170
3 9 17
3 10 145
3 11 111
3 12 97
3 13 56
3 14 129
4 5 82
4 6 11...

output:

432

result:

ok single line: '432'

Test #22:

score: 0
Accepted
time: 29ms
memory: 20040kb

input:

22 231
1 2 98
1 3 104
1 4 59
1 5 12
1 6 300
1 7 215
1 8 284
1 9 197
1 10 219
1 11 183
1 12 50
1 13 70
1 14 114
1 15 35
1 16 69
1 17 244
1 18 211
1 19 36
1 20 101
1 21 90
1 22 148
2 3 202
2 4 157
2 5 86
2 6 398
2 7 313
2 8 382
2 9 295
2 10 317
2 11 281
2 12 148
2 13 28
2 14 212
2 15 63
2 16 167
2 17 ...

output:

36

result:

ok single line: '36'

Test #23:

score: 0
Accepted
time: 30ms
memory: 20092kb

input:

23 253
1 2 285
1 3 105
1 4 161
1 5 32
1 6 243
1 7 296
1 8 286
1 9 207
1 10 125
1 11 20
1 12 205
1 13 263
1 14 81
1 15 245
1 16 146
1 17 26
1 18 173
1 19 195
1 20 109
1 21 69
1 22 64
1 23 100
2 3 180
2 4 446
2 5 317
2 6 42
2 7 11
2 8 1
2 9 492
2 10 410
2 11 305
2 12 80
2 13 22
2 14 204
2 15 530
2 16 ...

output:

248832

result:

ok single line: '248832'

Test #24:

score: 0
Accepted
time: 32ms
memory: 21120kb

input:

24 276
1 2 144
1 3 208
1 4 277
1 5 375
1 6 446
1 7 118
1 8 91
1 9 177
1 10 335
1 11 166
1 12 237
1 13 368
1 14 40
1 15 182
1 16 306
1 17 38
1 18 87
1 19 409
1 20 58
1 21 48
1 22 312
1 23 59
1 24 346
2 3 64
2 4 133
2 5 231
2 6 302
2 7 26
2 8 235
2 9 33
2 10 191
2 11 22
2 12 93
2 13 224
2 14 104
2 15 ...

output:

663552

result:

ok single line: '663552'

Test #25:

score: 0
Accepted
time: 34ms
memory: 19900kb

input:

23 253
1 2 250
1 3 128
1 4 54
1 5 274
1 6 216
1 7 201
1 8 115
1 9 78
1 10 58
1 11 183
1 12 149
1 13 294
1 14 63
1 15 270
1 16 211
1 17 43
1 18 142
1 19 103
1 20 35
1 21 202
1 22 1
1 23 11
2 3 376
2 4 196
2 5 26
2 6 33
2 7 49
2 8 136
2 9 171
2 10 307
2 11 67
2 12 101
2 13 46
2 14 312
2 15 20
2 16 39
...

output:

4

result:

ok single line: '4'

Test #26:

score: 0
Accepted
time: 33ms
memory: 20176kb

input:

23 253
1 2 104
1 3 92
1 4 5
1 5 52
1 6 181
1 7 30
1 8 29
1 9 44
1 10 70
1 11 150
1 12 201
1 13 9
1 14 29
1 15 136
1 16 135
1 17 231
1 18 149
1 19 105
1 20 55
1 21 31
1 22 171
1 23 11
2 3 12
2 4 99
2 5 155
2 6 76
2 7 74
2 8 76
2 9 61
2 10 174
2 11 46
2 12 97
2 13 113
2 14 133
2 15 31
2 16 239
2 17 12...

output:

4080

result:

ok single line: '4080'

Test #27:

score: 0
Accepted
time: 30ms
memory: 19896kb

input:

23 253
1 2 3
1 3 2
1 4 2
1 5 2
1 6 3
1 7 3
1 8 1
1 9 1
1 10 1
1 11 2
1 12 3
1 13 3
1 14 2
1 15 1
1 16 1
1 17 3
1 18 3
1 19 2
1 20 2
1 21 3
1 22 2
1 23 3
2 3 3
2 4 1
2 5 2
2 6 2
2 7 2
2 8 1
2 9 1
2 10 3
2 11 1
2 12 3
2 13 2
2 14 2
2 15 3
2 16 1
2 17 3
2 18 2
2 19 1
2 20 3
2 21 3
2 22 1
2 23 2
3 4 1
3...

output:

4

result:

ok single line: '4'

Test #28:

score: 0
Accepted
time: 31ms
memory: 19948kb

input:

6 15
1 2 1
1 3 3
1 4 2
1 5 1
1 6 1
2 3 2
2 4 1
2 5 2
2 6 1
3 4 3
3 5 3
3 6 1
4 5 3
4 6 1
5 6 2
4 3 2 6

output:

0

result:

ok single line: '0'

Test #29:

score: 0
Accepted
time: 34ms
memory: 20020kb

input:

8 28
1 2 1
1 3 4
1 4 4
1 5 2
1 6 3
1 7 3
1 8 4
2 3 5
2 4 3
2 5 3
2 6 5
2 7 1
2 8 3
3 4 3
3 5 1
3 6 5
3 7 5
3 8 4
4 5 2
4 6 4
4 7 2
4 8 3
5 6 1
5 7 5
5 8 4
6 7 2
6 8 2
7 8 3
1 5 8 4

output:

1

result:

ok single line: '1'

Test #30:

score: 0
Accepted
time: 23ms
memory: 20068kb

input:

5 10
1 2 1
1 3 5
1 4 2
1 5 5
2 3 2
2 4 3
2 5 2
3 4 4
3 5 5
4 5 4
2 1 4 3

output:

1

result:

ok single line: '1'

Test #31:

score: 0
Accepted
time: 25ms
memory: 20044kb

input:

24 23
1 8 182
2 8 860
2 24 972
3 11 461
3 15 716
4 18 11
4 20 653
5 6 982
5 16 184
6 18 52
7 10 703
7 19 957
8 23 182
9 13 53
10 14 454
11 24 525
12 13 53
13 17 493
14 20 578
15 21 373
16 22 209
17 19 72
21 22 540
9 23 12 1

output:

0

result:

ok single line: '0'

Test #32:

score: 0
Accepted
time: 29ms
memory: 20008kb

input:

18 49
1 3 143
1 11 431
1 13 431
1 14 349
1 17 372
2 4 595
2 7 108
2 8 849
2 9 622
2 18 622
3 4 670
3 5 498
3 7 967
3 8 543
3 10 164
3 12 999
3 15 178
4 6 71
4 14 493
4 16 887
4 17 112
5 11 431
5 13 431
5 14 884
5 17 339
6 7 118
6 8 61
6 9 622
6 18 622
7 14 700
7 16 361
7 17 469
8 14 786
8 16 905
8 1...

output:

0

result:

ok single line: '0'

Test #33:

score: 0
Accepted
time: 28ms
memory: 19948kb

input:

13 18
1 2 832
1 5 760
1 9 832
2 8 832
2 11 832
2 12 832
3 5 396
3 6 481
4 6 874
4 10 63
5 8 124
5 11 779
5 12 162
7 10 574
8 9 832
9 11 832
9 12 832
10 13 574
13 2 7 9

output:

0

result:

ok single line: '0'

Test #34:

score: 0
Accepted
time: 28ms
memory: 19908kb

input:

23 48
1 6 839
1 9 844
1 10 304
1 14 978
2 12 685
2 13 685
3 5 586
3 7 324
3 8 32
3 9 747
3 14 490
3 20 543
3 23 723
4 5 218
4 7 218
4 8 218
4 20 218
4 23 218
5 21 218
5 22 241
6 11 610
6 15 583
6 16 511
7 21 218
7 22 351
8 21 218
8 22 639
9 15 768
9 22 861
10 11 926
10 15 896
10 16 25
11 18 722
11 1...

output:

0

result:

ok single line: '0'

Test #35:

score: 0
Accepted
time: 25ms
memory: 20028kb

input:

24 140
1 2 465
1 3 712
1 4 786
1 5 371
1 8 234
1 9 173
1 11 802
1 13 43
1 14 850
1 17 898
1 18 531
1 21 43
2 6 735
2 7 661
2 10 317
2 12 980
2 15 60
2 16 60
2 19 76
2 20 195
2 22 744
2 23 802
2 24 477
3 6 323
3 7 431
3 10 287
3 12 801
3 15 60
3 16 60
3 19 160
3 20 811
3 22 41
3 23 395
3 24 63
4 6 72...

output:

0

result:

ok single line: '0'