QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#126437 | #995. 桥 | 1234567890# | WA | 32ms | 39380kb | C++14 | 2.5kb | 2023-07-18 15:01:09 | 2023-07-18 15:01:12 |
Judging History
answer
/*
灏忓簾鐗╋紝杩欓兘涓嶄細 /cf
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define inf (ll)1e9
#define pii pair <ll, ll>
#define fr first
#define se second
const ll mod = 1e9 + 7;
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
inline void write(ll x) {
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
inline ll quickmod(ll x, ll y) {
ll Ans = 1;
while(y) {
if(y & 1) Ans = (1ll * Ans * x) % mod;
x = (1ll * x * x) % mod;
y >>= 1;
}
return Ans;
}
inline void Add(ll &x, ll y) {
x += y;
if(x >= mod) x -= mod;
}
inline void Dec(ll &x, ll y) {
x -= y;
if(x < 0) x += mod;
}
inline ll add(ll x, ll y) {
x += y;
if(x >= mod) x -= mod;
return x;
}
inline ll dec(ll x, ll y) {
x -= y;
if(x < 0) x += mod;
return x;
}
struct UnionSet {
ll fa[200005];
inline void makeSet(ll x) {
for(ll i = 1; i <= x; i++) fa[i] = i;
}
inline ll findSet(ll x) {
if(x == fa[x]) return x;
return fa[x] = findSet(fa[x]);
}
inline void unionSet(ll x, ll y) {
x = findSet(x), y = findSet(y);
if(x == y) return ;
fa[x] = y;
}
}P;
ll n, m;
struct st {
ll v, id;
st() {}
st(ll A, ll B) {
v = A, id = B;
}
};
vector <st> G[100005];
ll U[500005], V[500005], vis[500005];
ll dfn[100005], low[100005], tot;
inline void Tarjan(ll x, ll fa) {
dfn[x] = low[x] = ++tot;
for(auto y : G[x]) {
if(y.id == fa) continue;
if(!dfn[y.v]) {
Tarjan(y.v, y.id);
if(low[y.v] > dfn[x]) vis[y.id] = 1;
low[x] = min(low[x], low[y.v]);
}
else low[x] = min(low[x], dfn[y.v]);
}
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read(), m = read();
P.makeSet(n);
for(ll i = 1; i <= m; i++) {
ll u = read(), v = read();
U[i] = u, V[i] = v;
G[u].push_back(st(v, i));
G[v].push_back(st(u, i));
P.unionSet(u, v);
}
for(ll i = 1; i <= n; i++) {
if(P.findSet(i) != P.findSet(1)) {
for(ll j = 1; j <= m; j++) vis[j] = 1;
break;
}
}
Tarjan(1, 0);
for(ll i = 1; i <= m; i++) if(vis[i]) write(U[i]), putchar(' '), write(V[i]), putchar('\n');
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 32ms
memory: 39380kb
input:
24942 387166 12556 21443 22404 16376 11073 24296 1535 11968 23745 2818 5073 12731 22550 14761 24118 12008 22695 18979 15118 13639 2080 8721 692 22578 22581 15267 9278 4127 7457 21674 17693 23448 10949 23429 9700 6009 14140 5064 7742 15164 17336 1662 18903 9760 17645 19575 6540 11942 11 4937 15282 10...
output:
result:
ok 0 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 20872kb
input:
10599 87159 4698 4000 60 4705 1476 5947 7273 1716 8004 3018 10094 1717 3092 3493 2613 9681 5427 3723 2510 6343 10113 6322 9257 634 4996 10197 9918 5582 6348 9561 10536 9777 8133 540 1917 7838 6666 2220 7951 815 2873 977 9397 4991 3529 1395 1426 3874 6379 9098 9504 3437 9076 9134 4321 3879 10252 9390...
output:
result:
ok 0 lines
Test #3:
score: -100
Wrong Answer
time: 26ms
memory: 28320kb
input:
43236 126833 40500 20695 21481 27642 28098 41772 412 7750 5862 39561 21777 22303 7868 21217 31658 34299 18532 10934 21931 31023 42926 15624 40332 18017 12484 8663 21927 7910 12504 17943 4379 10252 3523 21794 18641 1965 18633 25061 14639 10800 35958 1441 35044 20249 31491 38161 5749 4468 13403 8413 3...
output:
40500 20695 21481 27642 28098 41772 412 7750 5862 39561 21777 22303 7868 21217 31658 34299 18532 10934 21931 31023 42926 15624 40332 18017 12484 8663 21927 7910 12504 17943 4379 10252 3523 21794 18641 1965 18633 25061 14639 10800 35958 1441 35044 20249 31491 38161 5749 4468 13403 8413 34583 26855 40...
result:
wrong answer 1st lines differ - expected: '1349 20915', found: '40500 20695'