为什么会莫名RE
查看原帖
为什么会莫名RE
234775
Tenderfoot楼主2021/10/26 23:52

rt

开始调用快速幂的时候就RE了,但是我在快速幂函数中进入循环之前的第一行的调试信息也没输出出来

大大的疑惑

#include <bits/stdc++.h>

#define MAXN 1000010
#define Enter puts("")
#define Space putchar(' ')
#define int long long
#define Test puts("This is a Test")
#define Test_Begin Enter , puts("Test----------")
#define Test_End Enter , puts("-------------")

namespace IO
{
	static inline int Read()
	{
		int Ans(0);
		char Ch = getchar() , Las = ' ';

		while(!isdigit(Ch))
		{
			if(Ch == '-')
				Las = Ch;

			Ch = getchar();
		}
		while(isdigit(Ch))
		{
			Ans = Ans * 10 + Ch - '0';
			Ch = getchar();
		}

		if(Las == '-')
			Ans = -Ans;

		return Ans;
	}

	template <typename T> static inline void Write(T x)
	{
		if(x < 0)
			putchar('-') , x = -x;
		if(x >= 10)
			Write(x / 10);

		putchar(x % 10 + '0');
	}
};

using namespace IO;
using namespace std;

namespace Graph
{
    typedef struct Matrix
    {
        int a[1100][1100];
    };

    Matrix G , Ans;
    static int n , T , s , e , Cnt;
    static int p[MAXN];

    class Graph
    {
        protected: inline Matrix const Floyd(Matrix a , Matrix b)
        {
            Matrix Temp;
            memset(Temp.a , 0x3f , sizeof(Temp.a));

            for(register int k(1); k <= Cnt; k++)
                for(register int i(1); i <= Cnt; i++)
                    for(register int j(1); j <= Cnt; j++)
                        Temp.a[i][j] = min(Temp.a[i][j] , a.a[i][k] + b.a[k][j]);
//          Test;
            return Temp;
        }

        public: inline void const Power(int x)
        {
//        	Test;
            while(x)
            {
                if(x & 1)
                    Ans = Floyd(Ans , G);
                
                G = Floyd(G , G);
                x >>= 1;
            }
        }
    };

    Graph _G;

    static inline void const Main()
    {
        n = Read() , T = Read() , s = Read() , e = Read();
        memset(G.a , 0x3f , sizeof(G.a));
        memset(Ans.a , 0x3f , sizeof(Ans.a));

        while(T--)
        {
            int d = Read() , u = Read() , v = Read();
            
            if(!p[u])
                p[u] = ++Cnt;
            if(!p[v])
                p[v] = ++Cnt;
            
            G.a[p[u]][p[v]] = G.a[p[v]][p[u]] = min(d , G.a[p[v]][p[u]]);
//            Test;
        }

        for(register int i(1); i <= Cnt; i++)
            Ans.a[i][i] = 0;
//     	Test;   
        _G.Power(n);
        Write(Ans.a[p[s]][p[e]]) , Enter;
    }
};

signed main()
{
    Graph :: Main();

    return 0;
}
2021/10/26 23:52
加载中...