Submission #1095625

# Submission time Handle Problem Language Result Execution time Memory
1095625 2024-10-02T18:07:07 Z ivaziva Paths (BOI18_paths) C++14
70 / 100
323 ms 60756 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define MAXN 300001
#define MAXM 6

int n,m,k;
int a[MAXN];
vector<int> adj[MAXM][MAXN];
map<pair<int,int>,int> twonodes;

int32_t main()
{
    cin>>n>>m>>k;
    for (int i=1;i<=n;i++) cin>>a[i];
    int ans1=n,ans2=0,ans3=0,ans4=0,ans5=0;
    for (int i=1;i<=m;i++)
    {
        int x,y;cin>>x>>y;
        if (a[x]==a[y]) continue;
        adj[a[y]][x].push_back(y);
        adj[a[x]][y].push_back(x);
        ans2++;
    }
    for (int i=1;i<=n;i++)
    {
        for (int prva=1;prva<=k;prva++)
        {
            if (prva==a[i]) continue;
            for (int druga=prva+1;druga<=k;druga++)
            {
                if (druga==a[i]) continue;
                ans3+=adj[prva][i].size()*adj[druga][i].size();
            }
            for (int node:adj[prva][i])
            {
                for (int druga=1;druga<=k;druga++)
                {
                    if (druga==a[i] or druga==prva or adj[druga][node].size()==0) continue;
                    if (twonodes.find({druga,prva})==twonodes.end()) twonodes[{druga,prva}]=adj[druga][node].size();
                    else twonodes[{druga,prva}]+=adj[druga][node].size();
                }
            }
        }
        for (auto&p:twonodes)
        {
            pair<int,int> boje=p.first;int br=p.second;
            for (int prva=1;prva<=k;prva++)
            {
                if (prva==a[i] or prva==boje.first or prva==boje.second) continue;
                ans4+=br*adj[prva][i].size();
                if (k!=5) continue;
                int boja=15-a[i]-boje.first-boje.second-prva;
                if (twonodes.find({prva,boja})!=twonodes.end()) ans5+=br*twonodes[{prva,boja}];
                if (twonodes.find({boja,prva})!=twonodes.end()) ans5+=br*twonodes[{boja,prva}];
            }
        }
        twonodes.clear();
    }
    ans4/=2;
    if (k==1) cout<<0<<endl;
    else if (k==2) cout<<2*ans2<<endl;
    else if (k==3) cout<<2*(ans2+ans3)<<endl;
    else if (k==4) cout<<2*(ans2+ans3+ans4)<<endl;
    else cout<<2*(ans2+ans3+ans4+ans5)<<endl;
    return 0;
}

Compilation message

paths.cpp: In function 'int32_t main()':
paths.cpp:19:9: warning: unused variable 'ans1' [-Wunused-variable]
   19 |     int ans1=n,ans2=0,ans3=0,ans4=0,ans5=0;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42840 KB Output is correct
3 Correct 18 ms 42560 KB Output is correct
4 Correct 21 ms 42588 KB Output is correct
5 Correct 21 ms 42584 KB Output is correct
6 Correct 19 ms 42588 KB Output is correct
7 Correct 25 ms 42472 KB Output is correct
8 Correct 19 ms 42588 KB Output is correct
9 Correct 20 ms 42700 KB Output is correct
10 Correct 25 ms 42584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 50832 KB Output is correct
2 Correct 105 ms 49492 KB Output is correct
3 Correct 252 ms 58708 KB Output is correct
4 Correct 135 ms 50256 KB Output is correct
5 Correct 117 ms 46236 KB Output is correct
6 Correct 209 ms 56384 KB Output is correct
7 Correct 266 ms 58732 KB Output is correct
8 Correct 241 ms 59476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42840 KB Output is correct
3 Correct 18 ms 42560 KB Output is correct
4 Correct 21 ms 42588 KB Output is correct
5 Correct 21 ms 42584 KB Output is correct
6 Correct 19 ms 42588 KB Output is correct
7 Correct 25 ms 42472 KB Output is correct
8 Correct 19 ms 42588 KB Output is correct
9 Correct 20 ms 42700 KB Output is correct
10 Correct 25 ms 42584 KB Output is correct
11 Correct 149 ms 50832 KB Output is correct
12 Correct 105 ms 49492 KB Output is correct
13 Correct 252 ms 58708 KB Output is correct
14 Correct 135 ms 50256 KB Output is correct
15 Correct 117 ms 46236 KB Output is correct
16 Correct 209 ms 56384 KB Output is correct
17 Correct 266 ms 58732 KB Output is correct
18 Correct 241 ms 59476 KB Output is correct
19 Correct 126 ms 50936 KB Output is correct
20 Correct 106 ms 49496 KB Output is correct
21 Correct 284 ms 58920 KB Output is correct
22 Correct 141 ms 50256 KB Output is correct
23 Correct 127 ms 46232 KB Output is correct
24 Correct 202 ms 56388 KB Output is correct
25 Correct 254 ms 58836 KB Output is correct
26 Correct 280 ms 59476 KB Output is correct
27 Correct 102 ms 50256 KB Output is correct
28 Correct 139 ms 51792 KB Output is correct
29 Correct 323 ms 60752 KB Output is correct
30 Correct 247 ms 56760 KB Output is correct
31 Correct 228 ms 58116 KB Output is correct
32 Correct 314 ms 60756 KB Output is correct
33 Correct 20 ms 42584 KB Output is correct
34 Correct 19 ms 42588 KB Output is correct
35 Correct 20 ms 42588 KB Output is correct
36 Correct 20 ms 42500 KB Output is correct
37 Correct 18 ms 42588 KB Output is correct
38 Correct 17 ms 42712 KB Output is correct
39 Correct 21 ms 42588 KB Output is correct
40 Correct 19 ms 42588 KB Output is correct
41 Correct 20 ms 42588 KB Output is correct
42 Correct 17 ms 42600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 42584 KB Output is correct
2 Incorrect 60 ms 45392 KB Output isn't correct
3 Halted 0 ms 0 KB -