Language: C++

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<tuple>
#include<vector>
#include<iostream>
#include<algorithm>
#define maxn 100050
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
typedef long long ll;

int n,m,a,b,x;
struct graph
{
    int from[maxn],to[maxn],no;
    int head[maxn],nxt[maxn],val[maxn];
    ll dis[maxn];
    bool vis[maxn];
    inline void init()
    {
        memset(head,-1,sizeof(head));
        memset(vis,0,sizeof(vis));
        for(int i=0;i<=n;i++)dis[i]=INF;
        no=0;
    }
    inline void add(int a,int b,int x)
    {
        from[no]=a,to[no]=b;
        val[no]=x;
        nxt[no]=head[a];
        head[a]=no++;
    }
    void spfa(int st)
    {
        queue<int>q;
        vis[st]=1,dis[st]=0;
        q.push(st);
        while(!q.empty())
        {
            int u=q.front();
            q.pop();
            vis[u]=0;
            for(int i=head[u];i!=-1;i=nxt[i])
            {
                int v=to[i];
                if(dis[v]>dis[u]+val[i])
                {
                    dis[v]=dis[u]+val[i];
                    if(!vis[v])
                    {
                        vis[v]=1;
                        q.push(v);
                    }
                }
            }
        }
    }
}G,opG;

struct node
{
    int to[maxn],nxt[maxn],head[maxn],vis[maxn];
    int dfn[maxn],low[maxn],pre[maxn],val[maxn];
    int dep,no;
    map< tuple<int,int,int>,int >mo;
    void init()
    {
        memset(vis,0,sizeof(vis));
        memset(head,-1,sizeof(head));
        memset(dfn,-1,sizeof(dfn));
        memset(low,-1,sizeof(low));
        no=dep=0;
    }
    void add(int a,int b,int x)
    {
        val[no]=x;
        to[no]=b;
        nxt[no]=head[a];
        head[a]=no++;
    }
    void tarjan(int u,int fa)
    {
        dfn[u]=low[u]=++dep;
        vis[u]=1;
        for(int i=head[u];i!=-1;i=nxt[i])
        {
            int v=to[i];
            if(!vis[v])
            {
                tarjan(v,u);
                low[u]=min(low[u],low[v]);
                if(dfn[u]<low[v])
                {
                    if(u<v)mo[make_tuple(u,v,val[i])]++;
                    else mo[make_tuple(v,u,val[i])]++;
                }
            }
            else if(fa!=v)
                low[u]=min(low[u],dfn[v]);
        }
    }
    void solve()
    {
        tarjan(1,0);
        for(int i=1;i<=n;i++)
        {
            int v=pre[i];
            if(v>0&&low[i]>dfn[v])
            {
                //cout<<i<<" "<<v<<endl;
                if(i<v)mo[make_pair(i,v)]++;
                else mo[make_pair(v,i)]++;
            }
        }
    }
}DAG;

int main()
{
    scanf("%d%d",&n,&m);
    G.init(),opG.init();
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&a,&b,&x);
        G.add(a,b,x);
        opG.add(b,a,x);
    }
    G.spfa(1);
    opG.spfa(2);
    DAG.init();
    /*for(int i=1;i<=n;i++)
        cout<<G.dis[i]<<" ";
    cout<<endl;
    for(int i=1;i<=n;i++)
        cout<<opG.dis[i]<<" ";
    cout<<endl;*/
    for(int i=0;i<m;i++)
    {
        int u=G.from[i];
        int v=G.to[i];
        int w=G.val[i];
        if(G.dis[u]+w+opG.dis[v]==G.dis[2])
        {
            DAG.add(u,v,w);
            //cout<<u<<" "<<v<<endl;
        }
    }
    //cout<<endl;
    DAG.solve();
    for(int i=0;i<m;i++)
    {
        int u=G.from[i];
        int v=G.to[i];
        int w=G.val[i];
        if(G.dis[v]+w+opG.dis[u]<G.dis[2])
            printf("HAPPY\n");
        else
        {
            if(u>v)swap(u,v);
            if(DAG.mo[make_tuple(u,v,w)])
                printf("SAD\n");
            else printf("SOSO\n");
        }
    }
    return 0;
}



Compiler output:
a.cc: In member function 'void node::solve()':
a.cc:116:26: error: no match for 'operator[]' (operand types are 'std::map<std::tuple<int, int, int>, int>' and 'std::pair<int, int>')
  116 |                 if(i<v)mo[make_pair(i,v)]++;
      |                          ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::tuple<int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int>, int> >; mapped_type = int; key_type = std::tuple<int, int, int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::map<std::tuple<int, int, int>, int>::key_type&' {aka 'const std::tuple<int, int, int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::tuple<int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int>, int> >; mapped_type = int; key_type = std::tuple<int, int, int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::map<std::tuple<int, int, int>, int>::key_type&&' {aka 'std::tuple<int, int, int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:117:24: error: no match for 'operator[]' (operand types are 'std::map<std::tuple<int, int, int>, int>' and 'std::pair<int, int>')
  117 |                 else mo[make_pair(v,i)]++;
      |                        ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::tuple<int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int>, int> >; mapped_type = int; key_type = std::tuple<int, int, int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::map<std::tuple<int, int, int>, int>::key_type&' {aka 'const std::tuple<int, int, int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::tuple<int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int>, int> >; mapped_type = int; key_type = std::tuple<int, int, int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::map<std::tuple<int, int, int>, int>::key_type&&' {aka 'std::tuple<int, int, int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~