QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601980 | #9310. Permutation Counting 4 | zpt1376241 | WA | 0ms | 3588kb | C++23 | 2.0kb | 2024-09-30 17:15:00 | 2024-09-30 17:15:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define int __int128
using ll = long long;
typedef unsigned long long ull;
using ld = long double;
inline int read();
inline void write(int);
#define inf 0x3f3f3f3f // 1061109567
#define INF 0x3f3f3f3f3f3f3f3f // 4557430888798830399
#define lowbit(x) ((x) & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
// #define mp make_pair
#define PII pair<long, long>
#define fi first
#define se second
#define mem(x, y) memset(x, y, sizeof(x))
#define endl '\n'
const double PI = acos(-1.0);
#define eps 1e-7
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cerr << #x << ": " << x << endl;
const int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int maxn = 1e6 + 5;
const int mod = 998244353;
const int N = 1011;
int n;
int fa[maxn];
int rt(int x)
{
while (x != fa[x])
x = fa[x] = fa[fa[x]];
return x;
}
bool merge(int u, int v)
{
u = rt(u);
v = rt(v);
if (u == v)
return false;
fa[v] = u;
return true;
}
void solve()
{
cin >> n;
for (int i = 1; i <= n + 1; ++i)
fa[i] = i;
int ans = 1;
for (int i = 1; i <= n; ++i)
{
int l, r;
cin >> l >> r;
if (!merge(l, r + 1))
ans = 0;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// cout << fixed;
// cout.precision(18);
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch))
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch))
{
x = (x << 1) + (x << 3) + (ch ^ '0');
ch = getchar();
}
return x * f;
}
inline void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2
output:
0
result:
wrong answer Unexpected EOF in the participants output