QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414073#7986. 游戏aurorawhiteseaWA 41ms9816kbC++141.7kb2024-05-18 14:58:042024-05-18 14:58:04

Judging History

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

  • [2024-05-18 14:58:04]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:9816kb
  • [2024-05-18 14:58:04]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int head[100005], cnt, n, l, r, dep[100005], dep1[100005], num[100005];
vector<int>v[100005];

bool cmp1(int a, int b)
{
    if (dep1[a] != dep1[b])
        return dep1[a] < dep1[b];
    else return num[a] > num[b];
}
struct tree
{
    int to;
    int next;
}c[100005];
void add(int a, int b)
{
    v[a].push_back(b);
}
int dfs1(int x)
{
    if (v[x].size() == 0)
    {
        dep1[x]=1;
        return 1;
    }
    for (int i = 0; i<v[x].size(); i++)
    {
        int t=dfs1(v[x][i]);
        if(i==0)dep1[x]=t+1;
        else dep1[x]=min(dep1[x],t+1);
    }
    return dep1[x];
}
int dfs(int x)
{
    if (v[x].size() == 0)
    {
        num[x] = 1;
        return 1;
    }
    for (int i = 0; i < v[x].size(); i++)
    {
        if (dep1[v[x][i]] + 1 == dep1[x])
        {
            num[x] += dfs(v[x][i]);
        }
    }
    return num[x];
}
bool f(int x)
{
    if (dep1[x] == 1)
        return true;
    if (v[x].size() < 2)
        return false;
    sort(v[x].begin(), v[x].end(), cmp1);
    return f(v[x][1]);
}
int main()
{
    cin >> n;
    if( n == 1)
    {
        cout << "Wasted." << endl;
        return 0;
    }
    for (int i = 1; i <= n; i++)
    {
        dep1[i] = 0x3f3f3f3f;
    }
    for (int i = 1; i <= n - 1; i++)
    {
        cin >> l >> r;
        add(l, r);
    }
    dfs1(1);
    //cout<<endl;
    dfs(1);
    bool ff = f(1);
    if (ff)
    {
        cout << "You win, temporarily." << endl;
    }
    else
    {
        cout << "Wasted." << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6476kb

input:

6
1 2
2 3
2 4
1 5
5 6

output:

Wasted.

result:

ok single line: 'Wasted.'

Test #2:

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

input:

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

output:

You win, temporarily.

result:

ok single line: 'You win, temporarily.'

Test #3:

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

input:

1

output:

Wasted.

result:

ok single line: 'Wasted.'

Test #4:

score: 0
Accepted
time: 41ms
memory: 9792kb

input:

100000
86389 1
68115 86389
27661 68115
9669 27661
7343 9669
59420 7343
98078 59420
39321 98078
14847 39321
76863 14847
21104 14847
24241 39321
82708 39321
73282 82708
7424 39321
64358 7424
81481 39321
17105 81481
74205 17105
81202 98078
63636 81202
62429 63636
85827 62429
8648 62429
67963 63636
7287...

output:

You win, temporarily.

result:

ok single line: 'You win, temporarily.'

Test #5:

score: -100
Wrong Answer
time: 35ms
memory: 9816kb

input:

100000
28424 1
91124 28424
70268 91124
99456 70268
80696 99456
72802 80696
69700 72802
77527 72802
3835 80696
83715 3835
6690 3835
63240 3835
87789 80696
29903 99456
21234 29903
92544 21234
87569 21234
67361 29903
18146 67361
22916 67361
7024 99456
62805 7024
24624 7024
37895 7024
29126 99456
13746 ...

output:

You win, temporarily.

result:

wrong answer 1st lines differ - expected: 'Wasted.', found: 'You win, temporarily.'