社区讨论
请问为什么第五个点开不开O2是wa和ac的区别呢
P3275[SCOI2011] 糖果参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @locymi1w
- 此快照首次捕获于
- 2023/10/30 21:52 2 年前
- 此快照最后确认于
- 2023/11/05 08:14 2 年前
第五个点,开O2就ac不开就wa,在loj是可以过的,为什么会这样呢,有大佬告诉我一下嘛
CPP#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <bitset>
#include <time.h>
#include <string>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define ui unsigned int
// ios::sync_with_stdio(false);
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define ull unsigned long long
#define endd puts("");
#define re register
#define endl "\n"
#define int long long
//#define double long double
#define il inline
using namespace std;
#define PI 3.1415926535898
const double eqs = 1e-8;
const int max_ = 300000 + 7;
int mod = 1000000007;
const int inf = 2e9 + 7;
const long long INF = 2e18 + 7;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int dis[max_], cnt[max_], N, M, que[max_ * 10], R,L = 1;
bool inque[max_];
vector<pair<int, int> > xian[max_];
bool spfa() {
dis[0] = 1;
R = 0;
que[++R] = 0; inque[0] = 1;
int tou;
while (L <= R){
tou = que[L++];
inque[tou] = 0;
for (auto pa : xian[tou]) {
if (dis[pa.first] < dis[tou] + pa.second) {
dis[pa.first] = dis[tou] + pa.second;
cnt[pa.first] = cnt[tou] + 1;
if (cnt[pa.first] >= N + 1) {
return 0;
}
if (!inque[pa.first]) {
inque[pa.first] = 1;
que[++R] = pa.first;
}
}
}
}
return 1;
}
il void ini() {
N = read();M = read();
for (int i = 1; i <= N; i++) {
xian[0].push_back(make_pair(i, 0));
}
int op, A, B;
while (M--){
op = read(); A = read(); B = read();
if (op == 1) {
xian[B].push_back(make_pair(A, 0));
xian[A].push_back(make_pair(B, 0));
}if (op == 2) {
xian[A].push_back(make_pair(B, 1));
}if (op == 3) {
xian[B].push_back(make_pair(A, 0));
}if (op == 4) {
xian[B].push_back(make_pair(A, 1));
}if (op == 5) {
xian[A].push_back(make_pair(B, 0));
}
}
if (!spfa()) {
cout << "-1"; return;
}
int ans = 0;
for (int i = 1; i <= N; i++) {
ans += dis[i];
}
cout << ans;
}
signed main() {
ini();
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...