QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783999#3572. IdolSGColin#100 ✓10ms4104kbC++171.4kb2024-11-26 12:35:352024-11-26 12:36:35

Judging History

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

  • [2024-11-26 12:36:35]
  • 评测
  • 测评结果:100
  • 用时:10ms
  • 内存:4104kb
  • [2024-11-26 12:35:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define eb emplace_back
#define pb push_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

constexpr int N = 2007;

int n, m, scc, bel[N];

bool vis[N];

vector<int> e[N], re[N], order;

void dfs1(int u) {
    vis[u] = true;
    for (auto v : e[u]) if (!vis[v]) dfs1(v);
    order.eb(u);
}

void dfs2(int u) {
    bel[u] = scc;
    for (auto v : re[u]) if (!bel[v]) dfs2(v);
}

inline void work() {
    scc = 0;
    order.clear();
    rep(i, 1, (n << 1 | 1)) {
        e[i].clear();
        re[i].clear();
        vis[i] = false;
        bel[i] = 0;
    }
    // 2 * i : not advance
    // 2 * i + 1 : advance
    e[2].eb(3);
    rep(i, 1, m) {
        int x, y;
        cin >> x >> y;
        x = (x < 0 ? ((-x) << 1) : (x << 1 | 1));
        y = (y < 0 ? ((-y) << 1) : (y << 1 | 1));
        e[x ^ 1].eb(y); re[y].eb(x ^ 1);
        e[y ^ 1].eb(x); re[x].eb(y ^ 1);
    }
    rep(u, 2, (n << 1 | 1)) if (!vis[u]) dfs1(u);
    reverse(all(order));
    for (auto u : order) if (!bel[u]) {++scc; dfs2(u);}
    rep(i, 1, n) if (bel[i << 1] == bel[i << 1 | 1]) {puts("no"); return;}
    puts("yes");
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> n >> m) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 10ms
memory: 4104kb

input:

4 3
1 2
-2 -3
2 4
2 4
1 2
1 -2
-1 2
-1 -2
2 4
-1 2
1 2
-1 -2
1 -2
3 16
-1 2
-2 3
1 2
-2 3
-1 -2
2 3
1 -2
2 3
-1 2
-2 -3
1 2
-2 -3
-1 -2
2 -3
1 -2
2 -3
4 48
-1 2
-2 3
-3 4
1 2
-2 3
-3 4
-1 -2
2 3
-3 4
1 -2
2 3
-3 4
-1 2
-2 -3
3 4
1 2
-2 -3
3 4
-1 -2
2 -3
3 4
1 -2
2 -3
3 4
-1 2
-2 3
-3 -4
1 2
-2 3
-3 ...

output:

yes
no
no
no
no
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
no
yes
no
yes
yes
yes
no
no
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
ye...

result:

ok 117 lines