QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95819#5580. Branch Manager__#WA 96ms14288kbC++141.7kb2023-04-11 22:52:102023-04-11 22:52:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 22:52:13]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:14288kb
  • [2023-04-11 22:52:10]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")

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

#define el '\n'
#define F first
#define S second

typedef long long ll;
typedef long double ld;

bool multipleTestCases = 0, sublime = 0;
const int N = 2e5 + 5, INF = 1e9 + 5, mod = 1e9 + 7, LOG = 22, SQ = 500;

int n, q, qu[N], in[N], out[N], val[N], timer;
vector<int> g[N];
vector<pair<int, int>> ord;
bool fail;
int maxi = 2e5 + 5;
void dfs(int node)
{
    int ls = -1;
  //  cout << g[node].size() << endl;
    for (int i = 0;i < g[node].size();++i)
    {
        int cur = g[node][i];
       // cout << val[cur] << endl;
        if(!val[cur])
            continue;
        if(ls > val[cur])
            maxi = min(maxi, ls - 1);
        ls = val[cur];
    }
    for(auto &i : g[node])
        dfs(i);
}

void doWork()
{
    cin >> n >> q;

    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }

    for (int i = 1; i <= n; i++)
        sort(g[i].begin(), g[i].end());

    for (int i = 1; i <= q; i++)
    {
        cin >> qu[i];
        if ( !val[qu[i]])
             val[qu[i]] = i;
      //  cout << val[qu[i]] << endl;
    }
    dfs(1);
    cout << min(q,maxi) << el;
}
signed main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
#ifndef ONLINE_JUDGE
    if (sublime) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    int tests = 1;
    if (multipleTestCases) {
        cin >> tests;
    }
    for (int tc = 1; tc <= tests; tc++) {
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 5ms
memory: 10620kb

input:

4 4
1 2
1 3
1 4
3
2
3
4

output:

1

result:

ok single line: '1'

Test #3:

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

input:

2 2
1 2
2
2

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 96ms
memory: 14288kb

input:

200000 200000
161672 172858
146306 146322
61159 61510
140802 145171
194221 195447
73888 80278
77016 77115
1382 1417
186221 195091
78442 78451
171750 172141
147707 151432
182664 182798
143183 147414
156646 162546
6630 6706
18452 18519
99764 99811
153419 153707
125659 129068
179317 185954
13947 14278
...

output:

72713

result:

wrong answer 1st lines differ - expected: '3563', found: '72713'