当前位置: 首页 > news >正文

CCPC dongbei 2025 I

 题目链接:https://codeforces.com/gym/105924
题目背景:

        给定一个二分图,左图编号 1 ~ n,右图 n + 1 ~ 2n,左图的每个城市都会与右图的某个城市犯冲(每个城市都只与一个城市犯冲),除犯冲的城市外,不同侧的城市之间都有道路,给定起点与终点,请问是否可以到达(Yes or No)。

思路:

        分类讨论:在同侧,如果 n >= 3,一定有解。n < 3一定无解。在异侧只需判断是否犯冲即可。

       

        eq(同侧):可假设图为上图(连线为犯冲)。如果n = 3,s = 1,t = 2,可行路径就为 1 - 6 - 2,未经过犯冲城市。如果 n = 2,我们怎样走都会经过犯冲城市。

        特判:s == t。

数据范围:

        n 总和小于 2e5。

时间复杂度:

        O(n)

ac代码: 
#include <bits/stdc++.h>#define ioscc ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define me(a, x) memset(a, x, sizeof a)
#define all(a) a.begin(), a.end()
#define sz(a) ((int)(a).size())
#define pb(a) push_back(a)
using namespace std;typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<bool> vb;const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int MAX = (1ll << 31) - 1;
const int MIN = 1 << 31;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cout << a[i] << ' ';return os;
}template <class T>
istream &operator>>(istream &in, vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cin >> a[i];return in;
}/* 有乘就强转,前缀和开ll */void solve()
{int n, s, t;cin >> n >> s >> t;vi a(n + 10);for (int i = 1; i <= n; ++i)cin >> a[i];if (s == t){cout << "Yes" << endl;return;}if ((s <= n && t <= n) || (s > n && t > n)){if (n <= 2)cout << "No" << endl;elsecout << "Yes" << endl;}else{if ((s <= n && a[s] == t) || (t <= n && a[t] == s))cout << "No" << endl;elsecout << "Yes" << endl;}
}int main()
{ioscc;int T;cin >> T;while (T--)solve();return 0;
}

相关文章:

  • 《Pytorch深度学习实践》ch2-梯度下降算法
  • 怎么样提高研发质量?
  • 小白的进阶之路系列之九----人工智能从初步到精通pytorch综合运用的讲解第二部分
  • 多线程——定时任务ScheduledThreadPoolExecutor用法
  • [AD] CrownJewel-1 Logon 4799+vss-ShadowCopy+NTDS.dit/SYSTEM+$MFT
  • C++实现伽罗华域生成及四则运算(三)
  • AAA基础配置
  • Cypress + TypeScript + Vue3
  • CppCon 2014 学习: C++ on Mars
  • c++学习之---模版
  • CP4-OFDM模糊函数原理及仿真
  • day43 python Grad-CAM
  • 路由策略与路由控制
  • Global Security Markets 第5章知识点总结
  • 设计模式——策略设计模式(行为型)
  • 系统架构设计师(一):计算机系统基础知识
  • yolo目标检测助手:具有模型预测、图像标注功能
  • Day 36训练
  • Roller: 抽奖系统测试的幕后剧本-测试报告
  • 深度优先搜索(DFS)邻接矩阵实现
  • .net做网站用什么技术/百度产品优化排名软件
  • 广州网络建站/seo推广的全称是
  • 地区网站建设服务周到/男生最喜欢的浏览器推荐
  • 猪八戒网站做推广靠谱/关键词收录
  • 交易所网站建设教程/泰安seo网络公司
  • 做网站系统开发的意义/企业网页设计与推广