-
Notifications
You must be signed in to change notification settings - Fork 0
/
1146.cpp
60 lines (55 loc) · 1.02 KB
/
1146.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
59
60
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#define MMAX 2000
using namespace std;
struct V {
set<int> links;
};
V vs[MMAX];
int vNum, eNum;
vector<int> transfer(string s) {
stringstream ss;
vector<int> vt;
int i;
ss << s;
while(ss >> i) {
vt.push_back(i);
}
return vt;
}
bool find(vector<int> toPair) {
set<int> st;
for (auto p: toPair) {
for (auto l: vs[p].links) {
if (st.count(l)) return false;
}
st.insert(p);
}
return true;
}
int main() {
cin >> vNum >> eNum;
for (int e = 0; e < eNum; e++) {
int a, b;
cin >> a >> b;
vs[a].links.insert(b);
}
int k;
cin >> k;
cin.get();
bool flag = true;
for (int i = 0; i < k; i++) {
string s;
getline(cin, s);
vector<int> vt = transfer(s);
if (!find(vt)) {
if (flag) flag = false;
else cout << " ";
cout << i;
}
}
return 0;
}