| Hyacinth |
| Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB |
| Total submit users: 22, Accepted users: 17 |
| Problem 13350 : Special judge |
| Problem description |
|
As a new employee at the Northwestern Europe Rout- ing Company (NWERC), you do a lot of thinking about wireless network architectures. Lately you learned about a multi-channel mesh network architecture (called Hyacinth) that equips each mesh network node with multiple network interface cards (NICs) to increase the network throughput. You can choose a channel fre- quency for each NIC. In order to communicate, for every two network nodes that are in range of each other, their NICs must share at least one common frequency. The theoretical throughput is optimal when the total number of used frequencies in the network is maximal. |
| Input |
|
The input consists of: |
| Output |
|
Output a frequency assignment for each of the 2n NICs such that all adjacent nodes can communicate and the number of used frequencies is maximized. You should output n lines, where the ith line contains the two frequencies of network node i. Valid frequencies are nonnegative integers less than 10^9. |
| Sample Input |
2 1 2 14 1 2 1 3 1 4 2 5 2 6 3 7 4 8 4 9 4 10 7 11 7 12 7 13 7 14 |
| Sample Output |
23 42 42 23 4711 815 666 4711 4711 42 815 7 47 666 666 54 23 42 7 2 7 1 7 3 23 4 42 5 23 6 42 8 1 #include<algorithm> 2 #include<iostream> 3 #include<limits.h> 4 #include<stdlib.h> 5 #include<string.h> 6 #include<complex> 7 #include<cstring> 8 #include<iomanip> 9 #include<stdio.h> 10 #include<bitset> 11 #include<cctype> 12 #include<math.h> 13 #include<string> 14 #include<time.h> 15 #include<vector> 16 #include<cmath> 17 #include<queue> 18 #include<stack> 19 #include<list> 20 #include<map> 21 #include<set> 22 23 #define LL long long 24 25 using namespace std; 26 const LL mod = 1e9 + 7; 27 const double PI = acos(-1.0); 28 const double E = exp(1.0); 29 const int M = 1e4 + 5; 30 31 int a[M][2]; 32 int num[M]; 33 34 int main() 35 { 36 int n; 37 while( cin >> n ){ 38 int x, y; 39 int ans = 0; 40 memset(a, 0, sizeof(a)); 41 memset(num, 0, sizeof(num)); 42 for(int i = 0; i < n - 1; ++i){ 43 cin >> x >> y; 44 if(num[x] < 2 && num[y] < 2){ 45 ans++; 46 a[x][num[x]] = ans; 47 a[y][num[y]] = ans; 48 num[x]++; 49 num[y]++; 50 } 51 else if(num[x] == 2){ 52 a[y][num[y]] = a[x][1]; 53 num[y]++; 54 } 55 else if(num[y] == 2){ 56 a[x][num[x]] = a[y][1]; 57 num[x]++; 58 } 59 } 60 for(int i = 1; i <= n; ++i){ 61 if(a[i][1] == 0){ 62 ans++; 63 a[i][1] = ans; 64 } 65 cout << a[i][0] << " " << a[i][1] << endl; 66 } 67 } 68 return 0; 69 }
|
浙公网安备 33010602011771号