1. 程式人生 > >1154 Vertex Coloring

1154 Vertex Coloring

水題,秒殺

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <string>
 4 #include<algorithm>
 5 #include<vector>
 6 #include<cmath>
 7 #include<map>
 8 #include<set>
 9 #include <unordered_map>
10 
11 using namespace std;
12 
13 
14 int main(){
15 int v,e; 16 cin >> v >> e; 17 vector<int> m1[10001]; 18 19 for (int i = 0; i < e; i++) { 20 int v1, v2; 21 cin >> v1 >> v2; 22 m1[v1].push_back(v2); 23 } 24 25 int k; 26 cin >> k; 27 for (int i = 0; i < k; i++) {
28 short index[10001]; 29 set<int> s; 30 for (int j = 0; j < v; j++) { 31 int temp; 32 cin >> temp; 33 index[j] = temp; 34 s.insert(temp); 35 } 36 bool f = 0; 37 for (int j = 0; j < v; j++) { 38
for (int p = 0; p < m1[j].size(); p++) { 39 if (index[j] == index[m1[j][p]]) { 40 f = 1; 41 goto here; 42 } 43 } 44 } 45 here: 46 if (f == 1) { 47 printf("No\n"); 48 } 49 else { 50 cout << s.size() << "-coloring" << endl; 51 } 52 53 } 54 55 56 57 system("pause"); 58 59 };