Submission #674128

# Submission time Handle Problem Language Result Execution time Memory
674128 2022-12-23T09:39:20 Z QwertyPi Shell (info1cup18_shell) C++14
0 / 100
97 ms 49268 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 11;
vector<int> G[MAXN];
bool vis[MAXN];
vector<int> tp;
int n, m, p;
void dfs(int v){
	vis[v] = true;
	for(auto i : G[v]){
		if(!vis[i]) dfs(i);
	}
	tp.push_back(v);
}

int dp[MAXN], to[MAXN];

int32_t main(){
	cin.tie(0); cout.tie(0)->sync_with_stdio(false);
	cin >> n >> m >> p;
	vector<int> v; v.push_back(1);
	for(int i = 0; i < p; i++){
		int k; cin >> k; 
		if(k == 1){
			if(i == 0) continue;
			else {
				cout << 0 << endl;
				return 0;
			}
		}
		if(v.size() && k == v.back()) continue;
		v.push_back(k);
	}
	if(v.size() && v.back() != n) v.push_back(n);
	vector<pair<int, int>> vp, vp2;
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v;
		vp.push_back({u, v});
		G[u].push_back(v);
	}
	dfs(1);
	reverse(tp.begin(), tp.end());
	for(int i = 0; i < tp.size(); i++){
		to[tp[i]] = i + 1;
	}
	for(int i = 0; i <= n; i++){
		to[i] = i;
	}
	vector<int> d; d.push_back(0);
	for(int i = 0; i < p; i++){
		if(to[v[i]] == 0){
			cout << 0 << endl; return 0;
		}
		if(i != 0 && to[v[i - 1]] > to[v[i]]){
			cout << 0 << endl; return 0;
		}
		d.push_back(to[v[i]]);
	}
	if(v.back() != n) v.push_back(n);
	for(auto i : vp){
		if(to[i.fi] == 0 || to[i.se] == 0) continue;
		int f = to[i.fi], t = to[i.se];
		if(t > *upper_bound(d.begin(), d.end(), f)) continue;
		vp2.push_back({f, t});
	}
	sort(vp2.begin(), vp2.end());
	dp[1] = 1;
	for(auto i : vp2){
		dp[i.se] = (dp[i.fi] + dp[i.se]) % MOD;
	}
	cout << dp[(int) tp.size() - 1] << endl;
}

Compilation message

shell.cpp: In function 'int32_t main()':
shell.cpp:48:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0; i < tp.size(); i++){
      |                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24020 KB Output is correct
2 Correct 85 ms 36976 KB Output is correct
3 Correct 90 ms 43484 KB Output is correct
4 Incorrect 97 ms 49268 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -