QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747349#2683. British MenuactorWA 2ms10600kbC++142.4kb2024-11-14 16:57:362024-11-14 16:57:36

Judging History

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

  • [2024-11-14 16:57:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10600kb
  • [2024-11-14 16:57:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for (int i = (l); i <= (r); i++)
#define per(i,r,l) for (int i = (r); i >= (l); i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define maxn(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod = 998244353;
mt19937 gen(random_device{}());
ll rp(ll a,ll b) {ll res=1%mod;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N = 100100;
struct SCC {
    int size, tim, cnt;
    int dfn[N], low[N], bel[N], sz[N];
    bool ins[N];
    stack<int> stk;
    VI eg[N], ceg[N];

    void init(int n) {
        size = n;
        tim = cnt = 0;
        fill(dfn, dfn + 1 + n, 0);
        fill(sz, sz + 1 + n, 0);
        fill(ins, ins + 1 + n, false);
        while (!stk.empty()) stk.pop();
        rep(i,0,n) {
            eg[i].clear();
            ceg[i].clear();
        }
    }

    inline void add(int u, int v) {
        eg[u].push_back(v);
    }

    void dfs(int u) {
        dfn[u] = low[u] = ++tim;
        ins[u] = true;
        stk.push(u);
        for (auto v : eg[u]) {
            if (!dfn[v]) dfs(v);
            if (ins[v]) low[u] = min(low[u], low[v]);
        }
        if (dfn[u] == low[u]) {
            ++cnt;
            while (true) {
                int v = stk.top(); stk.pop();
                ins[v] = false;
                bel[v] = cnt;
                sz[cnt]++;
                if (v == u) break;
            }
        }
    }

    void tarjan() {
        rep(i,1,size) if (!dfn[i])
            dfs(i);
        rep(u,1,size)
            for (auto v : eg[u])
                if (bel[u] != bel[v])
                    ceg[bel[u]].pb(bel[v]);
    }
};
SCC g;
int n, m;
int dp[N];

int main() {
    scanf("%d%d", &n, &m);
    g.init(n);
    rep(i,1,m) {
        int u, v;
        scanf("%d%d", &u, &v);
        g.add(u, v);
    }
    g.tarjan();
    int ans = 0;
    rep(i,1,g.cnt) {
        for (auto j : g.ceg[i]) {
            assert(j < i);
            maxn(dp[i], dp[j]);
        }
        dp[i] += min(5, g.sz[i]);
        maxn(ans, dp[i]);
    }
    printf("%d\n", ans);
    return 0;
}

詳細信息

Test #1:

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

input:

10 6
7 8
4 2
8 6
5 1
4 1
4 5

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 10352kb

input:

10 10
1 3
8 9
6 10
1 2
7 9
10 9
5 1
2 5
8 6
7 8

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 2ms
memory: 9072kb

input:

10 8
7 6
4 2
10 6
4 5
2 4
3 2
6 10
2 1

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 2ms
memory: 9752kb

input:

10 19
3 6
9 10
7 9
9 8
8 7
5 6
3 8
6 9
5 9
2 6
6 8
1 4
6 7
6 10
3 9
10 7
4 9
10 8
1 8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 0ms
memory: 10600kb

input:

10 19
2 7
8 10
9 8
3 10
8 9
4 5
2 10
1 8
9 6
1 9
4 6
3 2
5 9
5 2
10 7
5 10
7 6
6 9
4 7

output:

8

result:

ok single line: '8'

Test #6:

score: 0
Accepted
time: 0ms
memory: 9600kb

input:

10 18
3 6
2 10
2 5
5 3
4 2
1 5
7 9
10 7
8 6
3 2
4 8
8 9
3 7
7 8
1 4
3 1
5 1
3 9

output:

9

result:

ok single line: '9'

Test #7:

score: 0
Accepted
time: 1ms
memory: 9344kb

input:

12 11
11 10
12 10
8 12
9 12
5 7
1 6
8 11
9 11
7 9
7 11
2 9

output:

5

result:

ok single line: '5'

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 9376kb

input:

7 7
1 2
2 3
3 4
4 5
5 6
6 2
4 7

output:

7

result:

wrong answer 1st lines differ - expected: '6', found: '7'