QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#55703 | #1972. JJ Rally | Three_Sannin# | TL | 2ms | 3552kb | C++ | 2.5kb | 2022-10-14 22:44:12 | 2022-10-14 22:44:15 |
Judging History
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=1; 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);
}
}
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;
adj[x].push_back({y , c});
adj[y].push_back({x , c});
}
for(int i=1; i<=n; i++)
dijk(i);
cin >> s >> t >> s2 >> t2;
for(int i=1; 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
dfs(s , 1<<s , t);
masks = all_masks;
all_masks.clear();
for(int i=1; i<=n; i++)
adj2[i].clear();
for(int i=1; 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);
assert(cnt <= (ll)3e9);
masks2 = all_masks;
ll ans = 0;
for(auto it : masks)
{
for(auto it2 : masks2)
{
if (it&it2) continue;
ans++;
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
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: 0ms
memory: 3512kb
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: 2ms
memory: 3548kb
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: -100
Time Limit Exceeded
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 ...