#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;
set<pair<int,int>> poseceni;
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() and poseceni.find({prva,boja})==poseceni.end()) ans5+=br*twonodes[{prva,boja}];
if (twonodes.find({boja,prva})!=twonodes.end() and poseceni.find({boja,prva})==poseceni.end()) ans5+=br*twonodes[{boja,prva}];
}
poseceni.insert(boje);
}
twonodes.clear();poseceni.clear();
}
ans4/=2,ans5/=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:20:9: warning: unused variable 'ans1' [-Wunused-variable]
20 | int ans1=n,ans2=0,ans3=0,ans4=0,ans5=0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
42588 KB |
Output is correct |
2 |
Correct |
10 ms |
42596 KB |
Output is correct |
3 |
Correct |
11 ms |
42840 KB |
Output is correct |
4 |
Correct |
10 ms |
42640 KB |
Output is correct |
5 |
Correct |
9 ms |
42588 KB |
Output is correct |
6 |
Correct |
9 ms |
42616 KB |
Output is correct |
7 |
Correct |
10 ms |
42584 KB |
Output is correct |
8 |
Correct |
9 ms |
42640 KB |
Output is correct |
9 |
Correct |
11 ms |
42588 KB |
Output is correct |
10 |
Correct |
11 ms |
42588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
48032 KB |
Output is correct |
2 |
Correct |
88 ms |
47188 KB |
Output is correct |
3 |
Correct |
260 ms |
54292 KB |
Output is correct |
4 |
Correct |
121 ms |
46980 KB |
Output is correct |
5 |
Correct |
99 ms |
42840 KB |
Output is correct |
6 |
Correct |
182 ms |
52148 KB |
Output is correct |
7 |
Correct |
238 ms |
54352 KB |
Output is correct |
8 |
Correct |
235 ms |
54864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
42588 KB |
Output is correct |
2 |
Correct |
10 ms |
42596 KB |
Output is correct |
3 |
Correct |
11 ms |
42840 KB |
Output is correct |
4 |
Correct |
10 ms |
42640 KB |
Output is correct |
5 |
Correct |
9 ms |
42588 KB |
Output is correct |
6 |
Correct |
9 ms |
42616 KB |
Output is correct |
7 |
Correct |
10 ms |
42584 KB |
Output is correct |
8 |
Correct |
9 ms |
42640 KB |
Output is correct |
9 |
Correct |
11 ms |
42588 KB |
Output is correct |
10 |
Correct |
11 ms |
42588 KB |
Output is correct |
11 |
Correct |
110 ms |
48032 KB |
Output is correct |
12 |
Correct |
88 ms |
47188 KB |
Output is correct |
13 |
Correct |
260 ms |
54292 KB |
Output is correct |
14 |
Correct |
121 ms |
46980 KB |
Output is correct |
15 |
Correct |
99 ms |
42840 KB |
Output is correct |
16 |
Correct |
182 ms |
52148 KB |
Output is correct |
17 |
Correct |
238 ms |
54352 KB |
Output is correct |
18 |
Correct |
235 ms |
54864 KB |
Output is correct |
19 |
Correct |
108 ms |
47956 KB |
Output is correct |
20 |
Correct |
92 ms |
47184 KB |
Output is correct |
21 |
Correct |
227 ms |
54352 KB |
Output is correct |
22 |
Correct |
120 ms |
46928 KB |
Output is correct |
23 |
Correct |
110 ms |
42840 KB |
Output is correct |
24 |
Correct |
185 ms |
52292 KB |
Output is correct |
25 |
Correct |
234 ms |
54356 KB |
Output is correct |
26 |
Correct |
260 ms |
55276 KB |
Output is correct |
27 |
Correct |
96 ms |
47956 KB |
Output is correct |
28 |
Correct |
119 ms |
48980 KB |
Output is correct |
29 |
Correct |
295 ms |
56144 KB |
Output is correct |
30 |
Correct |
213 ms |
52688 KB |
Output is correct |
31 |
Correct |
216 ms |
54272 KB |
Output is correct |
32 |
Correct |
329 ms |
56180 KB |
Output is correct |
33 |
Correct |
9 ms |
42584 KB |
Output is correct |
34 |
Correct |
10 ms |
42588 KB |
Output is correct |
35 |
Correct |
13 ms |
42584 KB |
Output is correct |
36 |
Correct |
11 ms |
42588 KB |
Output is correct |
37 |
Correct |
9 ms |
42644 KB |
Output is correct |
38 |
Correct |
10 ms |
42624 KB |
Output is correct |
39 |
Correct |
11 ms |
42612 KB |
Output is correct |
40 |
Correct |
12 ms |
42584 KB |
Output is correct |
41 |
Correct |
12 ms |
42584 KB |
Output is correct |
42 |
Correct |
10 ms |
42588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
42584 KB |
Output is correct |
2 |
Correct |
44 ms |
44628 KB |
Output is correct |
3 |
Correct |
41 ms |
45500 KB |
Output is correct |
4 |
Correct |
71 ms |
47956 KB |
Output is correct |
5 |
Correct |
61 ms |
47436 KB |
Output is correct |
6 |
Correct |
102 ms |
48824 KB |
Output is correct |
7 |
Correct |
37 ms |
44892 KB |
Output is correct |
8 |
Correct |
78 ms |
48464 KB |
Output is correct |
9 |
Correct |
69 ms |
47556 KB |
Output is correct |
10 |
Correct |
78 ms |
49704 KB |
Output is correct |
11 |
Correct |
86 ms |
47124 KB |
Output is correct |
12 |
Correct |
72 ms |
48324 KB |
Output is correct |
13 |
Correct |
70 ms |
47996 KB |
Output is correct |
14 |
Correct |
97 ms |
48972 KB |
Output is correct |
15 |
Correct |
90 ms |
48880 KB |
Output is correct |
16 |
Correct |
10 ms |
42584 KB |
Output is correct |
17 |
Correct |
12 ms |
42588 KB |
Output is correct |
18 |
Correct |
10 ms |
42588 KB |
Output is correct |
19 |
Correct |
9 ms |
42588 KB |
Output is correct |
20 |
Correct |
10 ms |
42588 KB |
Output is correct |
21 |
Correct |
10 ms |
42588 KB |
Output is correct |
22 |
Correct |
10 ms |
42588 KB |
Output is correct |
23 |
Correct |
11 ms |
42588 KB |
Output is correct |
24 |
Correct |
10 ms |
42620 KB |
Output is correct |
25 |
Correct |
10 ms |
42584 KB |
Output is correct |