AcWing 6105. 伊基的故事 IV - 潘达的诡计
原题链接
简单
作者:
陈佳北
,
2024-12-16 23:32:45
,
所有人可见
,
阅读 9
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> chords;
vector<bool> used(n, false);
bool invalid = false;
for(int i=0;i<m;i++){
int a, b;
cin >> a >> b;
if(a > b) swap(a, b);
if(used[a] || used[b]){
invalid = true;
}
used[a] = true;
used[b] = true;
chords.emplace_back(a, b);
}
if(invalid){
cout << "the evil panda is lying again";
return 0;
}
vector<vector<int>> adj(m, vector<int>());
for(int i=0;i<m;i++){
int a1 = chords[i].first;
int b1 = chords[i].second;
for(int j=i+1;j<m;j++){
int a2 = chords[j].first;
int b2 = chords[j].second;
if( (a1 < a2 && a2 < b1 && b1 < b2) || (a2 < a1 && a1 < b2 && b2 < b1) ){
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
vector<int> color(m, -1);
bool is_bipartite = true;
for(int i=0;i<m && is_bipartite;i++){
if(color[i] == -1){
queue<int> q;
q.push(i);
color[i] = 0;
while(!q.empty() && is_bipartite){
int u = q.front(); q.pop();
for(auto &v: adj[u]){
if(color[v] == -1){
color[v] = 1 - color[u];
q.push(v);
}
else if(color[v] == color[u]){
is_bipartite = false;
break;
}
}
}
}
}
if(is_bipartite){
cout << "panda is telling the truth...";
}
else{
cout << "the evil panda is lying again";
}
}
太强了哥😙