QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304851#8011. Instituteucup-team2000#WA 3ms22796kbC++202.9kb2024-01-14 04:14:272024-01-14 04:14:28

Judging History

你现在查看的是最新测评结果

  • [2024-01-14 04:14:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:22796kb
  • [2024-01-14 04:14:27]
  • 提交

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 = 500000, int MAXM = 500000>
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 = 500000, int MAXM = 500000>
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;
tarjan tt;
edge_list ee;
vector<pair<int, int>> tp2, tp1;
vector<int> adj[500005];
vector<int> outdeg(500005);

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    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); tp1.push_back({u, v});
        }
    }
    tt.solve(ee, n);

    for (auto pp : tp2) {
        if (tt.comp[pp.f] != tt.comp[pp.s]) {
            adj[tt.comp[pp.f]].push_back(tt.comp[pp.s]);
        }
    }
    for (auto pp : tp1) {
        if (tt.comp[pp.f] != tt.comp[pp.s]) outdeg[tt.comp[pp.f]]++;
    }
    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 (!vis[node]) {
                vis[node] = 1;
                if (outdeg[node] >= 1) {
                    cout << "Yes\n";
                    return 0;
                }
                q.push(node);
            }
        }
    }
    cout << "No\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 22392kb

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: 22404kb

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: -100
Wrong Answer
time: 3ms
memory: 22796kb

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:

No

result:

wrong answer expected YES, found NO