Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
CF: *1700
題意:(真難懂)
給定n種顏色的棋子,標號1-n,然後給定m個關係,即這兩個棋子是和諧的,可以連通
本題連通的意思就是在同一行或者同一列
讓你給出一種方案,使得:
1 每種顏色的棋子都有,
2 同種顏色的棋子必須直接連通或者間接聯通
3 相互和諧的棋子也必須有一個連通關係,不和諧的棋子不能有聯通
題意可以理解為:相同顏色的棋子要同行或者同列,m種和諧關係中,對於u-v,必須有一個u和v是同行或者同列的
思路:
顯然第i行 只放i顏色的棋子,然後第i行第x列放置一個i顏色的棋子,使之對應上面某一行的其他顏色的棋子,達到相互和諧的棋子有聯通的這個條件
為了不讓不和諧的棋子同行同列,要調整上述的x;
這裡我按列分成1000塊的大小,
#include<bits/stdc++.h>
using namespace std;
#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);
#define FI first
#define SE second
typedef long long ll;
typedef pair<ll,ll> P;
const int maxn = 100 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;
int n, m;
vector<int> vec[maxn];
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++i) {
int u, v; scanf("%d%d", &u, &v);
if(u != v) {
vec[u].push_back(v);
vec[v].push_back(u);
}
}
for(int i = 1; i <= n; ++i) {
printf("%d\n", vec[i].size()+1);
printf("%d %d\n", i*1000, i);
for(auto x : vec[i]) {
if(x > i) printf("%d %d\n", 1000*x+i, i);
else printf("%d %d\n", 1000*i+x, i);
}
}
return 0;
}
相關文章
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- Codeforces Round 986 (Div. 2)
- Codeforces Round 987 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 967 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 945 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #541 (Div. 2)
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Educational Codeforces Round 165 (Rated for Div. 2) C. Minimizing the Sum題解
- 2024.11.15 Codeforces Round 987(Div. 2)
- Codeforces Round 982 (Div. 2)(A~C)