QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826752#9772. Permutation Routingucup-team3586Compile Error//C++232.7kb2024-12-22 15:52:552024-12-22 15:52:55

Judging History

你现在查看的是最新测评结果

  • [2025-01-10 11:38:24]
  • hack成功,自动添加数据
  • (/hack/1438)
  • [2024-12-22 15:52:55]
  • 评测
  • [2024-12-22 15:52:55]
  • 提交

answer

print('???????')//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n;
vector<pii> G[1005];
int p[1005];
int dist[1005][1005];
void dfs(int u,int fa,int d,int *di)
{
	di[u]=d;
	for(auto pr:G[u])
	{
		int v=pr.first;
		if(v!=fa)
			dfs(v,u,d+1,di);
	}
}
vector<vector<int>> Answer;
int check()
{
	for(int i=1;i<=n;i++)
		if(p[i]!=i)
			return 0;
	return 1;
}
inline int sqr(int x){return x*x;}
int cost[1005];
int f[1005],g[1005];
pii ind[1005];
void dfs(int u,int fa)
{
	f[u]=-inf;
	g[u]=0;
	for(auto pr:G[u])
		if(pr.first!=fa)
		{
			dfs(pr.first,u);
			g[u]+=max(f[pr.first],g[pr.first]);
		}
	for(auto pr:G[u])
		if(pr.first!=fa)
		{
			int val=cost[pr.second]+g[u]-max(f[pr.first],g[pr.first])+g[pr.first];
			if(val>f[u])
			{
				f[u]=val;
				ind[u]=pr;
			}
		}
}
vector<int> Edges;
void construct(int u,int fa);
void constructF(int u,int fa);
void constructG(int u,int fa);
void construct(int u,int fa)
{
	if(f[u]>g[u]) constructF(u,fa);
	else constructG(u,fa);
}
void constructF(int u,int fa)
{
	Edges.pb(ind[u].second);
	swap(p[u],p[ind[u].first]);
	for(auto pr:G[u])
		if(pr.first!=fa)
			(pr==ind[u]?constructG:construct)(pr.first,u);
}
void constructG(int u,int fa)
{
	for(auto pr:G[u])
		if(pr.first!=fa)
			construct(pr.first,u);
}
void op()
{
	Edges.clear();
	for(int i=1;i<n;i++) cost[i]=0;
	for(int i=1;i<=n;i++)
		for(auto pr:G[i])
		{
			int j=pr.first;
			cost[pr.second]+=sqr(dist[i][p[i]])-sqr(dist[j][p[i]]);
		}
	dfs(1,0);
	construct(1,0);
	Answer.pb(Edges);
}
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		G[i].clear();
	for(int i=1;i<=n;i++)
		cin>>p[i];
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		G[u].pb(v,i);
		G[v].pb(u,i);
	}
	for(int i=1;i<=n;i++)
		dfs(i,0,0,dist[i]);
	Answer.clear();
	while(!check())
		op();
	cout<<sz(Answer)<<'\n';
	for(auto arr:Answer)
	{
		cout<<sz(arr)<<" ";
		for(auto E:arr)
			cout<<E<<" ";
		cout<<'\n';
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}

Details

answer.code:1:13: warning: trigraph ??' ignored, use -trigraphs to enable [-Wtrigraphs]
    1 | print('???????')//Author: Kevin
      |              
answer.code:1:7: warning: character constant too long for its type
    1 | print('???????')//Author: Kevin
      |       ^~~~~~~~~
answer.code:1:6: error: expected constructor, destructor, or type conversion before ‘(’ token
    1 | print('???????')//Author: Kevin
      |      ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:62,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:2:
/usr/include/c++/13/ext/type_traits.h:164:35: error: ‘constexpr const bool __gnu_cxx::__is_null_pointer’ redeclared as different kind of entity
  164 |   __is_null_pointer(std::nullptr_t)
      |                                   ^
/usr/include/c++/13/ext/type_traits.h:159:5: note: previous declaration ‘template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)’
  159 |     __is_null_pointer(_Type)
      |     ^~~~~~~~~~~~~~~~~
/usr/include/c++/13/ext/type_traits.h:164:26: error: ‘nullptr_t’ is not a member of ‘std’; did you mean ‘nullptr_t’?
  164 |   __is_null_pointer(std::nullptr_t)
      |                          ^~~~~~~~~
In file included from /usr/include/c++/13/cstddef:50,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:41:
/usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:443:29: note: ‘nullptr_t’ declared here
  443 |   typedef decltype(nullptr) nullptr_t;
      |                             ^~~~~~~~~
In file included from /usr/include/c++/13/bits/stl_pair.h:60,
                 from /usr/include/c++/13/bits/stl_algobase.h:64:
/usr/include/c++/13/type_traits:510:26: error: ‘std::size_t’ has not been declared
  510 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/13/type_traits:511:25: error: ‘_Size’ was not declared in this scope
  511 |     struct is_array<_Tp[_Size]>
      |                         ^~~~~
/usr/include/c++/13/type_traits:511:31: error: template argument 1 is invalid
  511 |     struct is_array<_Tp[_Size]>
      |                               ^
/usr/include/c++/13/type_traits:617:33: error: ‘nullptr_t’ is not a member of ‘std’; did you mean ‘nullptr_t’?
  617 |     struct is_null_pointer<std::nullptr_t>
      |                                 ^~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:443:29: note: ‘nullptr_t’ declared here
  443 |   typedef decltype(nullptr) nullptr_t;
      |                             ^~~~~~~~~
/usr/include/c++/13/type_traits:617:42: error: template argument 1 is invalid
  617 |     struct is_null_pointer<std::nullptr_t>
      |                                          ^
/usr/include/c++/13/type_traits:621:48: error: template argument 1 is invalid
  621 |     struct is_null_pointer<const std::nullptr_t>
      |                                                ^
/usr/include/c++/13/type_traits:625:51: error: template argument 1 is invalid
  625 |     struct is_null_pointer<volatile std::nullptr_t>
      |                                                   ^
/usr/include/c++/13/type_traits:629:57: error: template argument 1 is invalid
  629 |     struct is_null_pointer<const volatile std::nullptr_t>
      |                                                         ^
/usr/include/c++/13/type_traits:1348:37: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’?
 1348 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:214:23: note: ‘size_t’ declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/13/type_traits:1348:57: error: template argument 1 is invalid
 1348 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/13/type_traits:1357:37: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’?
 1357 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:214:23: note: ‘size_t’ declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/13/type_traits:1357:46: error: template argument 1 is invalid
 1357 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/13/type_traits:1359:26: error: ‘std::size_t’ has not been declared
 1359 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/13/type_traits:1360:21: error: ‘_Size’ was not declared in this scope
 1360 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/13/type_traits:1360:27: error: template argument 1 is inv...