Pagini recente » Cod sursa (job #2072115) | Cod sursa (job #3287621) | Cod sursa (job #744105) | Cod sursa (job #1643480) | Cod sursa (job #2491063)
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
map <int , bool> fq;
int const NM = 1 + 1e5;
struct code {
int x , y;
bool operator < (code r) const {
if (x == r . x)
return y < r . y;
return x < r . x;
}
};
map <code , int> mp;
int out (int c){
while (c --)
cout << "NOPE :/\n";
return 0;
}
int t [NM] ;
ll label [NM];
int main()
{
int i , n , m , cnt = 0 , from , to , comp = 1;
from = to = 0;
cin >> n >> m;
for(i = 1 ; i <= m ; ++ i){
int x , y , z;
cin >> x >> y >> z;
if (t [x] > t [y]){
swap (x , y);
z = -z;
}
code a = {from , to};
if (mp [a])
z -= mp [a];
if (t [x] != t [y] && t [x] && t [y]){
a = {from , to};
mp [a] = z;
}
t [x] = t [y] = comp;
if (! fq [x]){
fq [x] = ++ cnt;
x = cnt;
}
else
x = fq [x];
if (! fq [y]){
fq [y] = ++ cnt;
y = cnt;
}
else
y = fq [y];
if (x == y && z){
return out (m - i + 1);
}
if (i == 1)
label [x] = 0;
if (label [x]){
ll bx = label [x] , by = label [x] - z;
if (label [y] && label [y] != by)
return out (m - i + 1);
if (! label [y])
label [y] = by;
}
else{
if (label [y]){
ll by = label [y] , bx = label [y] - z;
if (label [x] && label [x] != bx)
return out (m - i + 1);
if (! label [x])
label [x] = bx;
}
else{
from = x , to = y;
label [x] = 0;
label [y] = label [x] - z;
++ t [x] , ++ t [y];
++ comp;
}
}
cout << "YEP :)\n";
}
return 0;
}