-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACSL09p4.cpp
58 lines (44 loc) · 1.02 KB
/
ACSL09p4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
set<int> ans;
vector<vector<int>> graph;
void dfs(int start, int node, vector<bool>& seen, bool& hasCycle) {
seen[node] = true;
for (auto n : graph[node]) {
if (n == start && seen[n]) {
hasCycle = true;
return;
}
else if (!seen[n]) {
dfs(start, n, seen, hasCycle);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
graph = vector<vector<int>>(n+1);
for (int i = 0; i < k; i++) {
int a, b, sa, sb;
cin >> a >> b >> sa >> sb;
if (sa > sb) {
graph[a].push_back(b);
}
if (sb > sa) {
graph[b].push_back(a);
}
}
int total = 0;
for (int i = 1; i <= n; i++) {
vector<bool> seen(n+1);
bool hasCycle = false;
dfs(i, i, seen, hasCycle);
total += hasCycle;
}
cout << total;
}