QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#304828 | #8011. Institute | ucup-team2000# | WA | 3ms | 9772kb | C++20 | 3.3kb | 2024-01-14 03:54:08 | 2024-01-14 03:54:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lep(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,b,a) for(int i = (b); i >= (a); i--)
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;
template<int MAXN = 100000, int MAXM = 100000>
struct edge_list {
int size, begin[MAXN], dest[MAXM], next[MAXM];
void clear (int n) { size = 0; fill(begin, begin + n, -1); }
edge_list (int n = MAXN) { clear(n); }
void add_edge(int u, int v) {
dest[size] = v; next[size] = begin[u]; begin[u] = size++;
}
};
template<int MAXN = 100000, int MAXM = 100000>
struct tarjan {
int comp[MAXN], size;
int dfn[MAXN], ind, low[MAXN], ins[MAXN], stk[MAXN], stks;
void dfs(const edge_list <MAXN, MAXM> &e, int i) {
dfn[i] = low[i] = ind++;
ins[i] = 1; stk[stks++] = i;
for (int x = e.begin[i]; ~x; x = e.next[x]) {
int j = e.dest[x];
if (!~dfn[j]) {
dfs(e, j);
if (low[i] > low[j]) low[i] = low[j];
} else if (ins[j] && low[i] > dfn[j]) {
low[i] = dfn[j];
}
}
if (dfn[i] == low[i]) {
for (int j = -1; j != i; j = stk[--stks], ins[j] = 0, comp[j] = size);
++size;
}
}
void solve(const edge_list <MAXN, MAXM> &e, int n) {
size = ind = stks = 0;
fill(dfn, dfn + n, -1);
for (int i = 0; i < n; ++i) {
if (!~dfn[i]) dfs(e, i);
}
}
};
void submit(int ans) {
cout << ans << "\n";
}
int n, m, u, v, ty;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
edge_list ee;
vector<pair<int, int>> tp2;
for (int i = 0; i < m; ++i) {
cin >> u >> v >> ty;
u--, v--;
if (ty == 1) {
tp2.push_back({u, v});
}
else {
ee.add_edge(u, v);
}
}
tarjan tt;
tt.solve(ee, n);
vector<int> adj[tt.size];
vector<int> outdeg(n);
for (auto pp : tp2) {
outdeg[tt.comp[pp.f]]++;
adj[tt.comp[pp.f]].push_back(tt.comp[pp.s]);
}
queue<int> q;
q.push(tt.comp[0]);
vector<bool> vis(n); vis[tt.comp[0]] = 1;
while (!q.empty()) {
int tp = q.front(); q.pop();
for (int node : adj[tp]) {
if (outdeg[node] >= 1) {
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
// for (auto pp : tp2) {
// ee.add_edge(pp.f, pp.s);
// }
// queue<int> q;
// q.push(0);
// vector<int> vis(n); vis[0] = 1;
// while (!q.empty()) {
// int tp = q.front(); q.pop();
// for (int x = ee.begin[tp]; ~x; x = ee.next[x]) {
// int node = ee.dest[x];
// if (!vis[node]) {
// vis[node] = 1;
// cout << tp << " " << node << endl;
// if (mm[{tp, node}] && tt.comp[tp] != tt.comp[node] && outdeg[node] >= 1) {
// cout << "Yes\n";
// return 0;
// }
// }
// }
// }
// cout << "No\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9688kb
input:
3 4 1 2 1 2 3 2 3 2 1 3 1 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 9688kb
input:
6 8 1 2 1 2 3 2 3 2 2 3 4 1 4 1 2 1 5 2 5 4 2 6 1 2
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 3ms
memory: 9736kb
input:
1000 1000 141 466 1 634 659 1 179 96 2 445 344 2 993 974 1 310 114 2 32 333 1 758 832 1 834 1 1 874 825 2 480 61 2 765 100 2 804 616 1 496 545 1 786 261 2 899 263 1 962 237 2 766 807 1 561 583 1 35 425 1 201 291 1 6 142 1 61 386 2 785 861 2 386 986 2 288 769 2 850 209 1 660 259 2 258 143 2 646 715 2...
output:
Yes
result:
ok answer is YES
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 9772kb
input:
1000 3000 719 279 2 857 23 1 984 625 2 904 509 2 892 456 2 589 195 2 718 932 2 608 363 1 474 672 1 217 993 2 165 895 2 727 329 2 932 404 2 952 146 2 201 272 2 412 895 2 228 267 2 396 365 2 813 794 2 259 250 1 968 764 2 100 76 2 924 665 2 981 931 2 292 975 2 903 649 2 793 101 2 54 703 1 853 58 2 356 ...
output:
No
result:
wrong answer expected YES, found NO