QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519338 | #8517. Interesting Paths | SocialPanda | WA | 0ms | 3880kb | C++23 | 1.6kb | 2024-08-14 18:49:20 | 2024-08-14 18:49:21 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#define int long long
//#define LL long long
#define double long double
//#define lf Lf
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define PII pair<int,int>
#define Gheap priority_queue<int,vector<int>,greater<int>>
#define Lheap priority_queue<int>
#define MAXN 0x3f3f3f3f
#define MINN -0x3f3f3f3f
using namespace std;
//const int N=1e6+100,M=2*N;
//int e[N],w[M],h[M],ne[M],idx;
struct pair_hash
{
template <class T1, class T2>
std::size_t operator() (const std::pair<T1, T2> &pair) const
{
return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
}
};
unordered_map<int,vector<int>> v,w;
unordered_map<int,int> mpA,mpB,mp;
unordered_map<PII,int,pair_hash> st;
int nn,mm;
int ans,num;
int n,m,fg=0;
void dfsA(int cur)
{
if(cur==n) fg=1;
mpA[cur]++;
for(auto z:v[cur])
{
st[{cur,z}]++;
dfsA(z);
}
}
void dfsB(int cur)
{
mpB[cur]++;
for(auto z:w[cur])
{
st[{z,cur}]++;
dfsB(z);
}
}
/*
*/
void solve()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
v[a].pb(b);
w[b].pb(a);
}
dfsA(1);
dfsB(n);
if(fg==0)
{
cout<<0;
return;
}
for(int i=1;i<=n;i++)
{
if(mpA[i] and mpB[i]) mp[i]++;
}
for(auto z:st)
{
if(mp[z.fi.fi] and mp[z.fi.se]) mm++;
}
nn=mp.size();
cout<<mm-nn+2<<endl;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
5 7 1 3 3 5 1 2 2 3 3 4 4 5 2 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
5 3 1 3 2 3 2 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
10 20 2 8 5 8 4 8 3 10 3 7 2 7 2 5 1 7 6 9 6 10 2 4 5 9 2 10 3 9 7 8 4 10 3 6 2 3 5 7 6 8
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
10 30 8 9 1 5 3 6 4 6 4 7 6 9 3 5 5 6 3 8 1 4 3 4 7 8 2 4 4 5 1 8 6 10 2 10 9 10 1 2 8 10 2 7 2 8 2 5 7 9 2 6 4 8 1 7 1 6 7 10 4 9
output:
18
result:
wrong answer 1st numbers differ - expected: '19', found: '18'