-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Ring_road.cpp
More file actions
44 lines (39 loc) · 1.15 KB
/
A_Ring_road.cpp
File metadata and controls
44 lines (39 loc) · 1.15 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll in[106], out[105];
int main()
{
ll t;
cin >> t;
ll i = 1;
while (t--)
{
ll need = 0, cost = 0;
ll n;
cin >> n;
while (n--)
{
ll a, b, c;
cin >> a >> b >> c;
if (in[a] || out[b] == 1) // jodi age ekbar travers hoy kunu node.and oita same vabe jdi abr travers hy tkn eita vul.like 1 5 and 1 6.eikane 1 thkei 2 bar edge ber hoisi.tai ei path ta tik nai
{
need += c;
in[b] = 1;
out[a] = 1;
}
else
{
in[a] = 1; // eikane jeta thke edge ber hoisa
out[b] = 1; // jetay edge dukse
}
cost += c; // total city r cost
}
/*.cout << "Case " << i
<< ":"
<< " ";
i++;/*/
cout << min(need, cost - need) << endl; // eikane need mane j gula wrong path ase.hoy ami wrong path tik krbo.otherwise wrong gulare ek raika baki full city tik krbo.jetay kom cost oita ans
// cout << need << " " << cost;
}
}