# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1095661 |
2024-10-02T20:24:29 Z |
ivaziva |
Paths (BOI18_paths) |
C++14 |
|
321 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,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: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 |
42584 KB |
Output is correct |
2 |
Correct |
20 ms |
42584 KB |
Output is correct |
3 |
Correct |
21 ms |
42580 KB |
Output is correct |
4 |
Correct |
21 ms |
42720 KB |
Output is correct |
5 |
Correct |
21 ms |
42708 KB |
Output is correct |
6 |
Correct |
22 ms |
42584 KB |
Output is correct |
7 |
Correct |
21 ms |
42584 KB |
Output is correct |
8 |
Correct |
20 ms |
42588 KB |
Output is correct |
9 |
Correct |
20 ms |
42716 KB |
Output is correct |
10 |
Correct |
20 ms |
42584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
50788 KB |
Output is correct |
2 |
Correct |
100 ms |
49672 KB |
Output is correct |
3 |
Correct |
278 ms |
58708 KB |
Output is correct |
4 |
Correct |
139 ms |
50260 KB |
Output is correct |
5 |
Correct |
116 ms |
46228 KB |
Output is correct |
6 |
Correct |
209 ms |
56380 KB |
Output is correct |
7 |
Correct |
252 ms |
58708 KB |
Output is correct |
8 |
Correct |
267 ms |
59472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
42584 KB |
Output is correct |
2 |
Correct |
20 ms |
42584 KB |
Output is correct |
3 |
Correct |
21 ms |
42580 KB |
Output is correct |
4 |
Correct |
21 ms |
42720 KB |
Output is correct |
5 |
Correct |
21 ms |
42708 KB |
Output is correct |
6 |
Correct |
22 ms |
42584 KB |
Output is correct |
7 |
Correct |
21 ms |
42584 KB |
Output is correct |
8 |
Correct |
20 ms |
42588 KB |
Output is correct |
9 |
Correct |
20 ms |
42716 KB |
Output is correct |
10 |
Correct |
20 ms |
42584 KB |
Output is correct |
11 |
Correct |
136 ms |
50788 KB |
Output is correct |
12 |
Correct |
100 ms |
49672 KB |
Output is correct |
13 |
Correct |
278 ms |
58708 KB |
Output is correct |
14 |
Correct |
139 ms |
50260 KB |
Output is correct |
15 |
Correct |
116 ms |
46228 KB |
Output is correct |
16 |
Correct |
209 ms |
56380 KB |
Output is correct |
17 |
Correct |
252 ms |
58708 KB |
Output is correct |
18 |
Correct |
267 ms |
59472 KB |
Output is correct |
19 |
Correct |
117 ms |
50884 KB |
Output is correct |
20 |
Correct |
107 ms |
49616 KB |
Output is correct |
21 |
Correct |
255 ms |
58772 KB |
Output is correct |
22 |
Correct |
140 ms |
50256 KB |
Output is correct |
23 |
Correct |
114 ms |
46228 KB |
Output is correct |
24 |
Correct |
196 ms |
56360 KB |
Output is correct |
25 |
Correct |
259 ms |
58844 KB |
Output is correct |
26 |
Correct |
252 ms |
59476 KB |
Output is correct |
27 |
Correct |
108 ms |
50260 KB |
Output is correct |
28 |
Correct |
135 ms |
51700 KB |
Output is correct |
29 |
Correct |
310 ms |
60752 KB |
Output is correct |
30 |
Correct |
225 ms |
56508 KB |
Output is correct |
31 |
Correct |
234 ms |
58172 KB |
Output is correct |
32 |
Correct |
321 ms |
60756 KB |
Output is correct |
33 |
Correct |
19 ms |
42584 KB |
Output is correct |
34 |
Correct |
20 ms |
42588 KB |
Output is correct |
35 |
Correct |
19 ms |
42588 KB |
Output is correct |
36 |
Correct |
17 ms |
42644 KB |
Output is correct |
37 |
Correct |
19 ms |
42588 KB |
Output is correct |
38 |
Correct |
18 ms |
42536 KB |
Output is correct |
39 |
Correct |
23 ms |
42588 KB |
Output is correct |
40 |
Correct |
18 ms |
42588 KB |
Output is correct |
41 |
Correct |
19 ms |
42584 KB |
Output is correct |
42 |
Correct |
17 ms |
42588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
42588 KB |
Output is correct |
2 |
Incorrect |
49 ms |
45480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |