-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBLINNET.cpp
More file actions
67 lines (61 loc) · 1.71 KB
/
BLINNET.cpp
File metadata and controls
67 lines (61 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
//#include<conio.h>
#define pb push_back
typedef pair<long,int> li;
typedef vector<li> vli;
vector < pair<long,int> > v[10010];
int n,t,k,x;
string s;
bool visited[10010];
long sum=0,y;
int main()
{
cin>>t;
while(t--)
{
sum=0;
memset(visited,false,sizeof(visited));
for(int i=0;i<10010;i++)
v[i].clear();
li temp;
priority_queue <li,vector<li>,greater<li> > pq;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s;
cin>>k;
while(k--)
{
cin>>x>>y;
temp=li(y,x);
v[i].pb(temp);
}
}
visited[1]=true;
int pos=1;
for(int i=1;i<n;i++)
{
for(int j=0;j<v[pos].size();j++)
pq.push(v[pos][j]);
while(1)
{
temp=pq.top();
pq.pop();
if(!visited[temp.second])
{
sum=sum+temp.first;
visited[temp.second]=true;
pos=temp.second;
break;
}
}
}
cout<<sum<<"\n";
}
//getch();
}