当前位置:网站首页>[C language brush leetcode] 1462. curriculum IV (m)
[C language brush leetcode] 1462. curriculum IV (m)
2022-07-26 02:00:00 【kinbo88】
【
You need a total of numCourses Course , The course numbers are 0 To numCourses-1 . You'll get an array prerequisite , among prerequisites[i] = [ai, bi] If you want to choose bi Course , you must Choose... First ai Course .
Some classes have direct prerequisite courses , For example, if you want to take a course 1 , You must take the course first 0 , Then it will be [0,1] The number of prerequisite courses is given in the form of number pairs .
The prerequisite can also be indirect Of . If the course a It's a course b prerequisites , Course b It's a course c prerequisites , So the course a It's the course c prerequisites .
You also get an array queries , among queries[j] = [uj, vj]. For the first j A query , You should answer the course uj Is it a course vj prerequisites .
Returns a Boolean array answer , among answer[j] It's No j The answer to a query .
Example 1:
Input :numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]
Output :[false,true]
explain : Course 0 Not a course 1 A prerequisite course for , But the course 1 It's a course 0 A prerequisite course for .
Example 2:
Input :numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]
Output :[false,false]
explain : There is no prerequisite course for , So each course is independent .
Example 3:
Input :numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]
Output :[true,true]
Tips :
2 <= numCourses <= 100
0 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)
prerequisites[i].length == 2
0 <= ai, bi <= n - 1
ai != bi
Each pair of [ai, bi] all Different
There is no ring in the prerequisite course map .
0 <= ui, vi <= n - 1
ui != vi
source : Power button (LeetCode)
link :https://leetcode.cn/problems/course-schedule-iv
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
】
A violent meal takes time 196ms, result AC 了
bool* checkIfPrerequisite(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){
int i, j, k;
int carr[numCourses][numCourses];
bool *retarr;
retarr = (bool *)malloc(sizeof(bool) * queriesSize);
*returnSize = queriesSize;
memset(carr, 0, sizeof(carr));
for (i = 0; i < prerequisitesSize; i++) {
carr[prerequisites[i][0]][prerequisites[i][1]] = 1; // Record the relationship between the pre selected courses given
}
for (i = 0; i < numCourses; i++) { // Find out all the relationships between the first courses , violence
for (j = 0; j < numCourses; j++) {
if (carr[i][j] == 1) {
for (k = 0; k < numCourses; k++) {
if (carr[k][i] == 1) {
carr[k][j] = 1;
}
}
}
}
}
for (i = 0; i < queriesSize; i++) {
if (carr[queries[i][0]][queries[i][1]] == 1) {
retarr[i] = true;
} else {
retarr[i] = false;
}
}
return retarr;
}边栏推荐
- flink sql 如何配置打印insert实参日志呢
- [Verilog digital system design (Xia Yuwen) 3 ----- basic concepts of Verilog syntax 1]
- P3166 number triangle (tolerance and exclusion +gcd)
- i.MX6ULL SNVS电源域GPIO状态保持验证
- My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
- D. Permutation restoration (greedy + double pointer)
- 怎么使用宝塔面板把node全栈项目部署到服务器上
- Common shell operations in Phoenix
- Niuke - bm39 serialized binary tree [hard]
- HTC手机官解、S-ON/S-OFF与超级CID的关系
猜你喜欢

Worthington nuclease and Micrococcus related research and determination scheme

【2019】【论文笔记】基于超材料可调谐THz宽频吸收——

【Verilog数字系统设计(夏宇闻)4-----Verilog语法的基本概念2】

How to display numbers / English time in Excel

SVN版本控制分支、合并功能使用

2022 love analysis ― bank digitalization practice report

Digital transformation behind the reshaping growth of catering chain stores

Navica tool imports remote MySQL into local MySQL database
![Web3.0 blog DAPP development practice [2022]](/img/18/f386246ff6ffbd0a42df57c3cd9170.png)
Web3.0 blog DAPP development practice [2022]

Pt onnx ncnn conversion problem record (followed by yolov5 training)
随机推荐
Pt onnx ncnn conversion problem record (followed by yolov5 training)
Digital transformation behind the reshaping growth of catering chain stores
D. Permutation restoration (greedy + double pointer)
How uxdb works on multiple processors
Common shell operations in Phoenix
Worthington papain - production of glycopeptides from purified proteoglycans (attached Literature)
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
Implementation of C iterator
The detailed knowledge summary of MySQL can be collected
NFT access tool premint was hacked and lost more than 370000 US dollars
Phoenix中常用shell操作
【LeetCode】32、 最长有效括号
PHP Alipay transfer to Alipay account
餐饮连锁门店重塑增长背后的数字化转型
How to display numbers / English time in Excel
阿里云Redis开发规范
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
A MCU event driven C framework
[untitled]